/*
 * > /*
 >  * INSANE - Interactive Structural Analysis Environment
 >  *
 >  * Copyright (C) 2003-2004
 >  * Universidade Federal de Minas Gerais
 >  * Escola de Engenharia
 >  * Departamento de Engenharia de Estruturas
 >  *
 >  * Author's email :     insane@dees.ufmg.br
 >  * Author's Website :   http://www.dees.ufmg.br/insane
 >  *
 >  * This program is free software; you can redistribute it and/or
 >  * modify it under the terms of the GNU General Public License
 >  * as published by the Free Software Foundation; either version 2
 >  * of the License, or any later version.
 >  *
 >  * This program is distributed in the hope that it will be useful,
 >  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 >  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 >  * GNU General Public License for more details.
 >  *
 >  * You should have received a copy of the GNU General Public License
 >  * along with this program; if not, write to the Free Software
 >  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 > 1307, USA.
 *
 */
package br.ufmg.dees.insane.ui.rich.postp.postp_controller;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;

import br.ufmg.dees.insane.commons.controller.Controller;
import br.ufmg.dees.insane.commons.view.IView;
import br.ufmg.dees.insane.draw.AxisDrawPerspective;
import br.ufmg.dees.insane.draw.Draw;
import br.ufmg.dees.insane.draw.FaceDraw;
import br.ufmg.dees.insane.draw.LineDraw;
import br.ufmg.dees.insane.draw.MarkDraw;
import br.ufmg.dees.insane.draw.NodalLoadDraw;
import br.ufmg.dees.insane.draw.RestraintsDraw;
import br.ufmg.dees.insane.draw.StringDraw;
import br.ufmg.dees.insane.model.geo.computationalGeometry.triangulation.Delaunay;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Edge;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Face;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.HalfEdge;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.HalfEdgeModel;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Loop;
import br.ufmg.dees.insane.model.geo.halfEdgeDataStructure.Vertex;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.Contour;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.ContourCalculator;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.EdgeViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.ElementsPlotContoursViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.FaceViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.GaussVertexViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.GeometricTransformation;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.MeshStateViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.NodalsPlotContoursViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.PostpView;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.PostpViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.ScaleColorsViewState;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.VertexViewState;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IPoint3d;

/**
 * The post-processor controller for this application.
 * @author Penna, S.S & Pitangueira, Roque
 * @since april 2005
 */
public class PostpController implements Controller{
	
	private HalfEdgeModel modelFemMesh;
	private HalfEdgeModel modelFemMeshState;
	private HalfEdgeModel modelGaussMesh;
	private IView view;
	
	private LinkedList<Face> faces ;
	private LinkedList<Edge> edges;
	private LinkedList<Vertex> vertices;
	private LinkedList<Vertex> gaussVertex;
	
	private LinkedList<HalfEdgeModel> trianglesHalfEdgesList = new LinkedList<HalfEdgeModel>();
	private LinkedList<Edge> triangulateEdges;
	private LinkedList<Face> tfaces ;
	
	private ArrayList<Draw> facesDraw;
	private ArrayList<Draw> vertexDraw;
	private ArrayList<Draw> gaussVertexDraw ;
	private ArrayList<Draw> deformedFacesDraw ;
	private ArrayList<Draw> deformedVertexDraw;
	private ArrayList<Draw> restraintsDraw;
	private ArrayList<Draw> restraintsOnMeshStateDraw;
	private ArrayList<Draw> nodalLoadsDraw;
	private ArrayList<Draw> nodalLoadsOnMeshStateDraw;
	private ArrayList<Object> selections;
	
	private String key = "";
	private LinkedList polygonsList = new LinkedList();
	private LinkedList polygonsMeshStateList = new LinkedList();
	private LinkedList resLimits = new LinkedList();
	
	private MeshStateViewState meshState;
	private EdgeViewState edgeState;
	private FaceViewState faceState;
	private VertexViewState vertexState;
	private GaussVertexViewState gaussVertexState;
	private ElementsPlotContoursViewState elementsPlotContoursState;
	private NodalsPlotContoursViewState nodalsPlotContoursState;
	private ScaleColorsViewState scaleColorsState;
	private GeometricTransformation geoTransform;
	public int width = 0;
	public int height = 0;
	private NumberFormat nf;
	
	/**
	 * The constructor method xyplot_controller, inicializes xymodel
	 * @param model a model
	 * @see XYPlotInterface
	 */
	public PostpController(ArrayList heModelList) {
		this.modelFemMesh = (HalfEdgeModel)heModelList.get(0);
		this.modelGaussMesh = (HalfEdgeModel)heModelList.get(1);
		this.edges = modelFemMesh.getEdgesList();
		this.vertices = modelFemMesh.getVerticesList();
		this.gaussVertex = modelGaussMesh.getVerticesList();
		this.faces = modelFemMesh.getFacesList();
		geoTransform = (((PostpViewState)this.view.getViewState()).getGeoTransformViewState()).getGeoTransform();
	}
	
	/**
	 * The constructor method xyplot_controller, inicializes XYPlot, IView 
	 * @param model a XYPlot model
	 * @param vs a IView
	 * @see XYPlotInterface
	 */
	public PostpController(ArrayList heModelList, IView vs) {
		this.modelFemMesh = (HalfEdgeModel)heModelList.get(0);
		this.modelGaussMesh = (HalfEdgeModel)heModelList.get(1);
		this.edges = modelFemMesh.getEdgesList();
		this.vertices = modelFemMesh.getVerticesList();
		this.gaussVertex = modelGaussMesh.getVerticesList();
		this.faces = modelFemMesh.getFacesList();
		this.view = vs;
		geoTransform = (((PostpViewState)this.view.getViewState()).getGeoTransformViewState()).getGeoTransform();
	}
	
	/**
	 * The constructor method xyplot_controller, inicializes IView 
	 * @param vs a IView
	 * @see XYPlotInterface
	 */
	public PostpController(IView vs) {
		faces = new LinkedList<Face>();
		edges = new LinkedList<Edge>();
		vertices = new LinkedList<Vertex>();
		gaussVertex = new LinkedList<Vertex>();
		selections = new ArrayList<Object>();
		this.view = vs;
		geoTransform = (((PostpViewState)this.view.getViewState()).getGeoTransformViewState()).getGeoTransform();
	}
	
	/**
	 * The constructor default, inicializes geoTransform 
	 */
	public PostpController() {
		geoTransform = (((PostpViewState)this.view.getViewState()).getGeoTransformViewState()).getGeoTransform();
	}
	
//	**************************************************************************************
	
	/**
	 * The method set XYPlot model
	 * @param newModel a new XYPlot model 
	 */
	public synchronized void setModel(ArrayList heModelList) {
		if(heModelList.size()==2){
			this.modelFemMesh = (HalfEdgeModel)heModelList.get(0);
			this.modelGaussMesh = (HalfEdgeModel)heModelList.get(1);
			this.gaussVertex = modelGaussMesh.getVerticesList();
			this.edges = modelFemMesh.getEdgesList();
			this.vertices = modelFemMesh.getVerticesList();
			this.faces = modelFemMesh.getFacesList();
			this.computeDeformedHalfEdge();
		}else{
			this.modelFemMesh = (HalfEdgeModel)heModelList.get(0);
			this.modelGaussMesh = (HalfEdgeModel)heModelList.get(0);
			this.gaussVertex = modelGaussMesh.getVerticesList();
			this.edges = modelFemMesh.getEdgesList();
			this.vertices = modelFemMesh.getVerticesList();
			this.faces = modelFemMesh.getFacesList();
			this.computeDeformedHalfEdge();
		}
		
	}
	
//	**************************************************************************************
	
	/**
	 * The method set XYPlotView 
	 * @param newView a new XYPlotView 
	 */
	public void setView(PostpView newView) {
		this.view = newView;
		meshState = ((PostpViewState)((PostpView)this.view).getViewState()).getMeshStateViewState();
		edgeState = ((PostpViewState)((PostpView)this.view).getViewState()).getEdgeViewState();
		faceState = ((PostpViewState)((PostpView)this.view).getViewState()).getFaceViewState();
		vertexState = ((PostpViewState)((PostpView)this.view).getViewState()).getVertexViewState();
		gaussVertexState = ((PostpViewState)((PostpView)this.view).getViewState()).getGaussVertexViewState();
		elementsPlotContoursState = ((PostpViewState)((PostpView)this.view).getViewState()).getElementsPlotContoursViewState();
		nodalsPlotContoursState = ((PostpViewState)((PostpView)this.view).getViewState()).getNodalsPlotContoursViewState();
		scaleColorsState = ((PostpViewState)((PostpView)this.view).getViewState()).getScaleColorsViewState();
	}
	
//	**************************************************************************************
	
	public double rr=0;
	
	public synchronized void draw(Graphics2D g) {
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		//drawing the restraints
		if(this.vertexState.isRestraintsOnOff()&&this.meshState.isMeshOnOff()){
			drawRestraints(g);
		}
		
		//drawing the restraints on the mesh State
		if(this.vertexState.isRestraintsOnOff()&&this.meshState.isMeshStateOnOff()){
			drawRestraintsOnMeshState(g);
		}
		
		//drawing the elements plot contours
		if(this.elementsPlotContoursState.isContourOnOff()){
			this.key = this.elementsPlotContoursState.getKeyValue();
			if(this.elementsPlotContoursState.isTriangulateWithNodesOnOff()){
				contourElementsDraw(g);
			}else if(!this.elementsPlotContoursState.isTriangulateWithNodesOnOff()&&!this.elementsPlotContoursState.isOnMesh()){
				contourGaussDraw(g);
			}else if(this.elementsPlotContoursState.isOnMesh()){
				contourNodeDraw(g);
			}
		}
		
		//drawing the elements plot contours on deformed shape
		if(this.elementsPlotContoursState.isContourMeshStateOnOff()){
			this.key = this.elementsPlotContoursState.getKeyValue();
			contourElementsDraw(g);
		}
		
		//drawing the elements plot contours
		if(this.elementsPlotContoursState.isDiscontinuosContourOnOff()){
			this.key = this.elementsPlotContoursState.getKeyValue();
			contourNodalsDiscontinuosDraw(g);
		}
		
		//drawing the nodal plot contours
		if(this.nodalsPlotContoursState.isContourOnOff()){
			this.key = this.nodalsPlotContoursState.getKeyValue();
			contourNodeDraw(g);
		}
		
		//drawing the nodal plot contours on deformed shape
		if(this.nodalsPlotContoursState.isContourMeshStateOnOff()){
			this.key = this.nodalsPlotContoursState.getKeyValue();
			contourNodeDrawOnMeshState(g);
		}
		
		//drawing the triangulation
		if(this.gaussVertexState.isGaussMeshOn()){
			drawTriangulation(g);
		}
		
		//Drawing the faces
		if(this.meshState.isMeshOnOff()){
			this.drawFemMeshFaces(g);
		}
		
		//Drawing the fem mesh vertex
		if(this.vertexState.isVertexOnOff()){
			this.drawFemMeshVertex(g);
		}
		
		//Drawing the the gauss vertex
		if(this.gaussVertexState.isGaussPointsOn()){
			this.drawGaussMeshVertex(g);
		}
		
		//drawing the deformed mesh
		if(meshState.isMeshStateOnOff()){  
			this.drawDeformedFemMeshFaces(g);
		}
		
		//Drawing the fem mesh vertex state
		if(this.vertexState.isVertexOnOff()&&meshState.isMeshStateOnOff()){
			this.drawDeformedFemMeshVertex(g);
		}
		
		if(this.scaleColorsState.isScaleContoursOnOff()){
			
			if(this.scaleColorsState.getScalePosition().equals("Left")){
				drawScaleLeft(g);
			}
			if(this.scaleColorsState.getScalePosition().equals("Right")){
				drawScaleRight(g);
			}
			if(this.scaleColorsState.getScalePosition().equals("Bottom")){
				drawScaleBottom(g);
			}
			if(this.scaleColorsState.getScalePosition().equals("Top")){
				drawScaleTop(g);
			}
			
		} 
		
		if(((PostpViewState)this.view.getViewState()).isGlobalAxisOn()){
			this.drawGlobalAxis(g);
		}
		
		/*if(!this.scaleColorsState.isScaleContoursOnOff()){
			this.drawLocalAxis(g);
		}*/
		
		//drawing the nodal loads
		if(this.vertexState.isLoadOnOff()&&this.meshState.isMeshOnOff()){
			drawNodalLoads(g);
		}
		
//		drawing the nodal loads
		if(this.vertexState.isLoadOnOff()&&this.meshState.isMeshStateOnOff()){
			drawNodalLoadsOnMeshState(g);
		}
		
	}
	
//	**************************************************************************************
	
	public synchronized void drawRestraints(Graphics2D g){
//		Draws supports
		Draw draw;
		g.setColor(Color.GREEN);
		
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		ListIterator sts = restraintsDraw.listIterator();
		while(sts.hasNext()) {
			draw = (Draw)sts.next();
			draw.draw(g);
		}
	}
	
	public synchronized void drawNodalLoads(Graphics2D g){
//		Draws supports
		Draw draw;
		g.setColor(Color.BLUE);
		g.setStroke(new BasicStroke((float)1.5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		ListIterator sts = nodalLoadsDraw.listIterator();
		while(sts.hasNext()) {
			draw = (Draw)sts.next();
			// vertex = (Vertex)draw.getRepresents();
			// IPoint3d p3 = vertex.getCoords();
			//  draw.setLocation(this.view.getDrawingArea().getViewPoint( new Point2D.Double(p3.x, p3.y) ));
			draw.setScale(1);
			draw.draw(g);
		}
	}
	
	public synchronized void drawRestraintsOnMeshState(Graphics2D g){
//		Draws supports
		Draw draw;
		g.setColor(Color.GREEN);
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		ListIterator sts = restraintsOnMeshStateDraw.listIterator();
		while(sts.hasNext()) {
			draw = (Draw)sts.next();
			draw.draw(g);
		}
	}
	
	public synchronized void drawNodalLoadsOnMeshState(Graphics2D g){
//		Draws supports
		Draw draw;
		g.setColor(Color.GREEN);
		g.setStroke(new BasicStroke((float)2.5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		ListIterator sts = nodalLoadsOnMeshStateDraw.listIterator();
		while(sts.hasNext()) {
			draw = (Draw)sts.next();
			// vertex = (Vertex)draw.getRepresents();
			// IPoint3d p3 = vertex.getCoords();
			//  draw.setLocation(this.view.getDrawingArea().getViewPoint( new Point2D.Double(p3.x, p3.y) ));
			draw.setScale(1);
			draw.draw(g);
		}
	}
	
	public void drawScaleLeft(Graphics2D g){
		//Draw draw;
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		if(this.scaleColorsState.isScaleContoursOnOff()){
			// int w = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().width;
			// int h = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().height;
			
			if(this.scaleColorsState.isBackgroundOnOff()){
				g.setColor(this.view.getViewState().bgcolor);
				g.fillRect(0,0,125,this.view.getDrawingArea().getHeight());
				g.setStroke(new BasicStroke((float)(this.view.getViewState().gridLineWidth), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				g.setColor(this.view.getViewState().gridColor);
			}
			
			//drawing the contour range scale
			LinkedList palette = this.scaleColorsState.getColorsPalette();
			int deltaY = 25;
			int factor = 12;
			for (int i = 0; i < palette.size(); i++) {
				g.setColor((Color)palette.get(i));
				if(palette.size()==32){
					g.fillRect(5,10+deltaY,15,factor);
					deltaY = deltaY+factor;
				}else if(palette.size()==8){
					g.fillRect(5,10+deltaY,15,4*factor);
					deltaY = deltaY+4*factor;
				}
			}
			
			if(this.view.getViewState().bgcolor.getRed()==0
					&&this.view.getViewState().bgcolor.getGreen()==0
					&&this.view.getViewState().bgcolor.getBlue()==0||
					this.view.getViewState().bgcolor==Color.BLACK
					||this.view.getViewState().bgcolor==Color.black){
				g.setColor(Color.WHITE);
			}else{
				g.setColor(Color.BLACK);
			}
			
			g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			
			if(this.scaleColorsState.isBoundaryOnOff()){
				g.drawRect(5,35,15,384);
			}
			//drawing the values of contour range scale
			NumberFormat f; 
			f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
			f.setMaximumFractionDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			
			deltaY=25; 
			
			Font temp = g.getFont();
			g.setFont(new Font("Arial",Font.PLAIN,10));
			for (int i = 0; i < resLimits.size(); i++) {
				g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				
				if(palette.size()==32){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(20,10+deltaY,25,10+deltaY);
						g.drawString(  f.format((Double)resLimits.get(i)),27,10+deltaY);
					}
					deltaY+=12*8;
					i+=7;
				}else if(palette.size()==8){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(20,10+deltaY,25,10+deltaY);
						g.drawString(  f.format((Double)resLimits.get(i)),27,10+deltaY);
					}
					deltaY+=12*8;
					i+=1;
				}
			}
			
			if(palette.size()==32){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(20,10+deltaY,25,10+deltaY);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),27,10+deltaY);
				}
			}else if(palette.size()==8){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(20,10+384,25,10+deltaY);
				}
				g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),27,10+deltaY);
			}
			
			if(this.scaleColorsState.getInfoPosition().equals("TL1")){
				g.drawString("Value: "+this.key,5,35);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,75);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BL2")){
				g.drawString("Value: "+this.key,5,430);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,450);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,10+470);
			}
			if(this.scaleColorsState.getInfoPosition().equals("TR3")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,75);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,35);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BR4")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),450);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),470);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),490);
			}
			
			g.setFont(temp);
			
		}
		
		//g.setStroke(new BasicStroke((float)2.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		//g.drawLine(0,this.view.getDrawingArea().getHeight()-1,this.view.getDrawingArea().getWidth(),this.view.getDrawingArea().getHeight()-1);
		
	}
	
	public void drawScaleRight(Graphics2D g){
		//Draw draw;
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		if(this.scaleColorsState.isScaleContoursOnOff()){
			//  int w = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().width;
			//  int h = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().height;
			
			if(this.scaleColorsState.isBackgroundOnOff()){
				g.setColor(this.view.getViewState().bgcolor);
				g.fillRect(this.view.getDrawingArea().getWidth()-125,0,this.view.getDrawingArea().getWidth(),this.view.getDrawingArea().getHeight());
				g.setStroke(new BasicStroke((float)(this.view.getViewState().gridLineWidth), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			}
			
			//drawing the contour range scale
			LinkedList palette = this.scaleColorsState.getColorsPalette();
			int deltaY = 25;
			int factor = 12;
			for (int i = 0; i < palette.size(); i++) {
				g.setColor((Color)palette.get(i));
				if(palette.size()==32){
					g.fillRect(this.view.getDrawingArea().getWidth()-20,deltaY,15,factor);
					deltaY = deltaY+factor;
				}else if(palette.size()==8){
					g.fillRect(this.view.getDrawingArea().getWidth()-20,deltaY,15,4*factor);
					deltaY = deltaY+4*factor;
				}
			}
			
			if(this.view.getViewState().bgcolor.getRed()==0
					&&this.view.getViewState().bgcolor.getGreen()==0
					&&this.view.getViewState().bgcolor.getBlue()==0||
					this.view.getViewState().bgcolor==Color.BLACK
					||this.view.getViewState().bgcolor==Color.black){
				g.setColor(Color.WHITE);
			}else{
				g.setColor(Color.BLACK);
			}
			
			g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			
			if(this.scaleColorsState.isBoundaryOnOff()){
				g.drawRect(this.view.getDrawingArea().getWidth()-20,25,15,384);
			}
			
			//drawing the values of contour range scale
			NumberFormat f; 
			f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
			f.setMaximumFractionDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			deltaY=25; 
			
			Font temp = g.getFont();
			g.setFont(new Font("Arial",Font.PLAIN,10));
			for (int i = 0; i < resLimits.size(); i++) {
				g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				if(palette.size()==32){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(this.view.getDrawingArea().getWidth()-20,deltaY,this.view.getDrawingArea().getWidth()-25,deltaY);
						g.drawString(  f.format((Double)resLimits.get(i)),this.view.getDrawingArea().getWidth()-32-7*((PostpViewState)this.view.getViewState()).getFracDigits(),deltaY);
					}
					deltaY+=12*8;
					i+=7;
				}else if(palette.size()==8){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(this.view.getDrawingArea().getWidth()-20,deltaY,this.view.getDrawingArea().getWidth()-25,deltaY);
						g.drawString(  f.format((Double)resLimits.get(i)),this.view.getDrawingArea().getWidth()-32-7*((PostpViewState)this.view.getViewState()).getFracDigits(),deltaY);
					}
					deltaY+=12*8;
					i+=1;
				}
			}
			
			if(palette.size()==32){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(this.view.getDrawingArea().getWidth()-20,deltaY,this.view.getDrawingArea().getWidth()-25,deltaY);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-32-7*((PostpViewState)this.view.getViewState()).getFracDigits(),deltaY);
				}
			}else if(palette.size()==8){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(this.view.getDrawingArea().getWidth()-20,deltaY,this.view.getDrawingArea().getWidth()-25,deltaY);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-32-7*((PostpViewState)this.view.getViewState()).getFracDigits(),deltaY);
				}
			}
			
			
			if(this.scaleColorsState.getInfoPosition().equals("TL1")){
				g.drawString("Value: "+this.key,5,35);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,75);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BL2")){
				g.drawString("Value: "+this.key,5,430);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,450);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,10+470);
			}
			if(this.scaleColorsState.getInfoPosition().equals("TR3")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,35);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,75);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BR4")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),450);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),470);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-85-7*((PostpViewState)this.view.getViewState()).getFracDigits(),490);
			}
			
			g.setFont(temp);
			
		}
		
		//g.setStroke(new BasicStroke((float)2.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		//g.drawLine(0,this.view.getDrawingArea().getHeight()-1,this.view.getDrawingArea().getWidth(),this.view.getDrawingArea().getHeight()-1);
		
	}
	
	public void drawScaleBottom(Graphics2D g){
		//Draw draw;
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		if(this.scaleColorsState.isScaleContoursOnOff()){
			// int w = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().width;
			//  int h = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().height;
			
			if(this.scaleColorsState.isBackgroundOnOff()){
				g.setColor(this.view.getViewState().bgcolor);
				g.fillRect(0,this.view.getDrawingArea().getHeight()-65,this.view.getDrawingArea().getWidth(),65);
				g.setStroke(new BasicStroke((float)(this.view.getViewState().gridLineWidth), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				g.setColor(this.view.getViewState().gridColor);
			}
			
			//drawing the contour range scale
			LinkedList palette = this.scaleColorsState.getColorsPalette();
			int deltaX = this.view.getDrawingArea().getWidth()/2-240;
			int factor = 15;
			for (int i = 0; i < palette.size(); i++) {
				g.setColor((Color)palette.get(i));
				if(palette.size()==32){
					g.fillRect(deltaX,this.view.getDrawingArea().getHeight()-40,factor,15);
					deltaX += factor;
				}else if(palette.size()==8){
					g.fillRect(deltaX,this.view.getDrawingArea().getHeight()-40,4*factor,15);
					deltaX += 4*factor;
				}
			}
			
			if(this.view.getViewState().bgcolor.getRed()==0
					&&this.view.getViewState().bgcolor.getGreen()==0
					&&this.view.getViewState().bgcolor.getBlue()==0||
					this.view.getViewState().bgcolor==Color.BLACK
					||this.view.getViewState().bgcolor==Color.black){
				g.setColor(Color.WHITE);
			}else{
				g.setColor(Color.BLACK);
			}
			
			g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			
			if(this.scaleColorsState.isBoundaryOnOff()){
				g.drawRect(this.view.getDrawingArea().getWidth()/2-240,this.view.getDrawingArea().getHeight()-40
						,480,15);
			}
			
			//drawing the values of contour range scale
			NumberFormat f; 
			f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
			f.setMaximumFractionDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			deltaX=this.view.getDrawingArea().getWidth()/2-240;  
			
			Font temp = g.getFont();
			g.setFont(new Font("Arial",Font.PLAIN,10));
			for (int i = 0; i < resLimits.size(); i++) {
				g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				if(palette.size()==32){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(deltaX,this.view.getDrawingArea().getHeight()-43,deltaX,this.view.getDrawingArea().getHeight()-40);
						g.drawString(  f.format((Double)resLimits.get(i)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,this.view.getDrawingArea().getHeight()-45);
					}
					deltaX+=15*8;
					i+=7;
				}else if(palette.size()==8){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(deltaX,this.view.getDrawingArea().getHeight()-43,deltaX,this.view.getDrawingArea().getHeight()-40);
						g.drawString(  f.format((Double)resLimits.get(i)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,this.view.getDrawingArea().getHeight()-45);
					}
					deltaX+=15*8;
					i+=1;
				}
			}
			
			if(palette.size()==32){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(deltaX,this.view.getDrawingArea().getHeight()-43,deltaX,this.view.getDrawingArea().getHeight()-40);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,this.view.getDrawingArea().getHeight()-45);
				}
			}else if(palette.size()==8){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(deltaX,this.view.getDrawingArea().getHeight()-43,deltaX,this.view.getDrawingArea().getHeight()-40);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,this.view.getDrawingArea().getHeight()-45);
				}
			}
			
			if(this.scaleColorsState.getInfoPosition().equals("TL1")){
				g.drawString("Value: "+this.key,5,35);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,75);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BL2")){
				g.drawString("Value: "+this.key,5,430);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,450);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,470);
			}
			if(this.scaleColorsState.getInfoPosition().equals("TR3")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,75);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,35);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BR4")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-50);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-30);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-10);
			}
			g.setFont(temp);
		}
		
	}
	
	public void drawScaleTop(Graphics2D g){
		//Draw draw;
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		if(this.scaleColorsState.isScaleContoursOnOff()){
			// int w = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().width;
			//  int h = (int)((InterfacePostp)((PostpView)this.view).getInterface()).getSize().height;
			
			if(this.scaleColorsState.isBackgroundOnOff()){
				g.setColor(this.view.getViewState().bgcolor);
				g.fillRect(0,0,this.view.getDrawingArea().getWidth(),50);
				g.setStroke(new BasicStroke((float)(this.view.getViewState().gridLineWidth), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				g.setColor(this.view.getViewState().gridColor);
			}
			
			//drawing the contour range scale
			LinkedList palette = this.scaleColorsState.getColorsPalette();
			int deltaX = this.view.getDrawingArea().getWidth()/2-240;
			int factor = 15;
			for (int i = 0; i < palette.size(); i++) {
				g.setColor((Color)palette.get(i));
				if(palette.size()==32){
					g.fillRect(deltaX,5,factor,15);
					deltaX += factor;
				}else if(palette.size()==8){
					g.fillRect(deltaX,5,4*factor,15);
					deltaX += 4*factor;
				}
			}
			
			if(this.view.getViewState().bgcolor.getRed()==0
					&&this.view.getViewState().bgcolor.getGreen()==0
					&&this.view.getViewState().bgcolor.getBlue()==0||
					this.view.getViewState().bgcolor==Color.BLACK
					||this.view.getViewState().bgcolor==Color.black){
				g.setColor(Color.WHITE);
			}else{
				g.setColor(Color.BLACK);
			}
			
			g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			
			if(this.scaleColorsState.isBoundaryOnOff()){
				g.drawRect(this.view.getDrawingArea().getWidth()/2-240,5,480,15);
			}
			
			//drawing the values of contour range scale
			NumberFormat f; 
			f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
			f.setMaximumFractionDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			deltaX=this.view.getDrawingArea().getWidth()/2-240;  
			
			Font temp = g.getFont();
			g.setFont(new Font("Arial",Font.PLAIN,10));
			for (int i = 0; i < resLimits.size(); i++) {
				g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				if(palette.size()==32){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(deltaX,20,deltaX,23);
						g.drawString(  f.format((Double)resLimits.get(i)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,40);
					}
					deltaX+=15*8;
					i+=7;
				}else if(palette.size()==8){
					if(this.scaleColorsState.isBoundaryOnOff()){
						g.drawLine(deltaX,20,deltaX,23);
						g.drawString(  f.format((Double)resLimits.get(i)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,40);
					}
					deltaX+=15*8;
					i+=1;
				}
			}
			
			if(palette.size()==32){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(deltaX,20,deltaX,23);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,40);
				}
			}else if(palette.size()==8){
				if(this.scaleColorsState.isBoundaryOnOff()){
					g.drawLine(deltaX,20,deltaX,23);
					g.drawString(f.format((Double)resLimits.get(resLimits.size()-1)),deltaX-((PostpViewState)this.view.getViewState()).getFracDigits()*2,40);
				}
			}
			
			if(this.scaleColorsState.getInfoPosition().equals("TL1")){
				g.drawString("Value: "+this.key,5,35);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,75);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BL2")){
				g.drawString("Value: "+this.key,5,430);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),5,450);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),5,470);
			}
			if(this.scaleColorsState.getInfoPosition().equals("TR3")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,75);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,55);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,35);
			}
			if(this.scaleColorsState.getInfoPosition().equals("BR4")){
				g.drawString("Value: "+this.key,this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-50);
				g.drawString("Min.: "+f.format((Double)resLimits.get(0)),this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-30);
				g.drawString("Max.: "+f.format((Double)resLimits.get(resLimits.size()-1)),this.view.getDrawingArea().getWidth()-150,this.view.getDrawingArea().getHeight()-10);
			}
			g.setFont(temp);
		}
		
	}
	
	public double[] center(Face f) {
		LinkedList verticesList = new LinkedList();
		verticesList = this.modelFemMesh.getVerticesFace((Face)f);
		double x=0;
		double y=0;
		double z=0;
		for(int i=0;i<verticesList.size();i++){
			IMatrix m = new IMatrix(4,4);
			m = geoTransform.getMatrix();
			IMatrix pt = new IMatrix(1,4);
			pt.setElement(0,0,((Vertex)verticesList.get(i)).getCoords().x);
			pt.setElement(0,1,((Vertex)verticesList.get(i)).getCoords().y);
			pt.setElement(0,2,((Vertex)verticesList.get(i)).getCoords().z);
			pt.setElement(0,3,1);
			pt.mul(m);
			x+= pt.getElement(0,0);
			y+= pt.getElement(0,1);
			z+= pt.getElement(0,2);
		}
		double[] d = new double[2];
		d[0] = x/verticesList.size();
		d[1] = y/verticesList.size();
		return d;
	}
	
	public double[] center(Edge e) {
		LinkedList<Vertex> verticesList = new LinkedList<Vertex>();
		verticesList.add(e.getVStart());
		verticesList.add(e.getVEnd());
		double x=0;
		double y=0;
		double z=0;
		for(int i=0;i<verticesList.size();i++){
			IMatrix m = new IMatrix(4,4);
			m = geoTransform.getMatrix();
			IMatrix pt = new IMatrix(1,4);
			pt.setElement(0,0,((Vertex)verticesList.get(i)).getCoords().x);
			pt.setElement(0,1,((Vertex)verticesList.get(i)).getCoords().y);
			pt.setElement(0,2,((Vertex)verticesList.get(i)).getCoords().z);
			pt.setElement(0,3,1);
			pt.mul(m);
			x+= pt.getElement(0,0);
			y+= pt.getElement(0,1);
			z+= pt.getElement(0,2);
		}
		double[] d = new double[2];
		d[0] = x/verticesList.size();
		d[1] = y/verticesList.size();
		return d;
	}
	
//	**************************************************************************************
	
	public void triangulate(){
		trianglesHalfEdgesList = new LinkedList<HalfEdgeModel>();
		
		NumberFormat f; 
		f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		f.setMaximumFractionDigits(5);
		
		HalfEdgeModel fem = modelFemMesh;
		HalfEdgeModel gauss = modelGaussMesh;
		for (int i = 0; i < this.faces.size() ; i++) {
			LinkedList<Vertex> vertices = new LinkedList<Vertex>();
			//adding the first vertex of fem mesh of this face i.
			Face faceFem = new Face(((Face)fem.getFacesList().get(i)).getId(),(Loop)((Face)fem.getFacesList().get(i)).getLoopList().get(0));
			Vertex vertexAuxFem = (Vertex)fem.getVerticesFace(faceFem).get(0);
			IPoint3d pfem = new IPoint3d( new Double(f.format(((Vertex)vertexAuxFem).getCoords().x))
					,new Double(f.format(((Vertex)vertexAuxFem).getCoords().y))
					,new Double(f.format(((Vertex)vertexAuxFem).getCoords().z)));
			Vertex vfem = new Vertex(vertexAuxFem.getId(),pfem);
			vfem.setValues(((Vertex)vertexAuxFem).getValues());
			vertices.add(vfem);
			
			//adding the first vertex of gauss mesh of this face i.
			Face faceGauss =  new Face(((Face)gauss.getFacesList().get(i)).getId(),(Loop)((Face)gauss.getFacesList().get(i)).getLoopList().get(0));
			Vertex vertexAuxGauss = (Vertex)gauss.getVerticesFace(faceGauss).get(gauss.getVerticesFace(faceGauss).size()-1);
			IPoint3d pGauss = new IPoint3d( new Double(f.format(((Vertex)vertexAuxGauss).getCoords().x))
					,new Double(f.format(((Vertex)vertexAuxGauss).getCoords().y))
					,new Double(f.format(((Vertex)vertexAuxGauss).getCoords().z)));
			Vertex vgauss = new Vertex(vertexAuxGauss.getId(),pGauss);
			vgauss.setValues(((Vertex)vertexAuxGauss).getValues());
			vertices.add(vgauss);
			
			//adding the others vertices of the fem mesh
			Face face = (Face)fem.getFacesList().get(i);
			for (int j = 1; j < fem.getVerticesFace(face).size(); j++) {
				LinkedList<Vertex> aux = new LinkedList<Vertex>();
				aux = fem.getVerticesFace(face);
				IPoint3d p = new IPoint3d( new Double(f.format( ((Vertex)aux.get(j)).getCoords().x) )
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().y))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().z)));
				Vertex v = new Vertex(((Vertex)aux.get(j)).getId(),p);
				v.setValues(((Vertex)aux.get(j)).getValues());
				vertices.add(v);
			}
			
			//adding the others vertices of the gauss mesh
			face =  (Face)gauss.getFacesList().get(i);
			for (int j = 0; j < gauss.getVerticesFace(face).size()-1; j++) {
				LinkedList<Vertex> aux = new LinkedList<Vertex>();
				aux = fem.getVerticesFace(face);
				IPoint3d p = new IPoint3d( new Double(f.format(((Vertex)aux.get(j)).getCoords().x))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().y))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().z)));
				Vertex v = new Vertex(((Vertex)aux.get(j)).getId(),p);
				v.setValues(((Vertex)aux.get(j)).getValues());
				vertices.add(v);
			}
			Delaunay del = new Delaunay(vertices);
			del.compute();
			trianglesHalfEdgesList.add(del.fillHalfEdge());
		}
	}
	
	public void triangulateNodalPoints(){
		trianglesHalfEdgesList = new LinkedList<HalfEdgeModel>();
		NumberFormat f; 
		f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		f.setMaximumFractionDigits(5);
		
		HalfEdgeModel fem = modelFemMesh;
		for (int i = 0; i < this.faces.size() ; i++) {
			LinkedList<Vertex> vertices = new LinkedList<Vertex>();
			//adding the first vertex of fem mesh of this face i.
			Face faceFem = new Face(((Face)fem.getFacesList().get(i)).getId(),(Loop)((Face)fem.getFacesList().get(i)).getLoopList().get(0));
			Vertex vertexAuxFem = (Vertex)fem.getVerticesFace(faceFem).get(fem.getVerticesFace(faceFem).size()-1);
			IPoint3d pfem = new IPoint3d( new Double(f.format(((Vertex)vertexAuxFem).getCoords().x))
					,new Double(f.format(((Vertex)vertexAuxFem).getCoords().y))
					,new Double(f.format(((Vertex)vertexAuxFem).getCoords().z)));
			Vertex vfem = new Vertex(vertexAuxFem.getId(),pfem);
			vfem.setValues(((Vertex)vertexAuxFem).getValues());
			vertices.add(vfem);
			
			//adding the others vertices of the fem mesh
			Face face = (Face)fem.getFacesList().get(i);
			for (int j = 0; j < fem.getVerticesFace(face).size()-1; j++) {
				LinkedList aux = new LinkedList();
				aux = fem.getVerticesFace(face);
				IPoint3d p = new IPoint3d( new Double(f.format( ((Vertex)aux.get(j)).getCoords().x) )
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().y))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().z)));
				Vertex v = new Vertex(((Vertex)aux.get(j)).getId(),p);
				v.setValues(((Vertex)aux.get(j)).getValues());
				vertices.add(v);
			}
			Delaunay del = new Delaunay(vertices);
			del.compute();
			trianglesHalfEdgesList.add(del.fillHalfEdge());
		}
	}
	
	public void triangulateGaussPoints(){
		trianglesHalfEdgesList = new LinkedList<HalfEdgeModel>();
		NumberFormat f; 
		f = (DecimalFormat)NumberFormat.getNumberInstance(Locale.UK);
		f.setMaximumFractionDigits(5);
		
		HalfEdgeModel fem = modelFemMesh;
		HalfEdgeModel gauss = modelGaussMesh;
		for (int i = 0; i < this.faces.size() ; i++) {
			LinkedList<Vertex> vertices = new LinkedList<Vertex>();
			//adding the first vertex of gauss mesh of this face i.
			Face faceGauss =  new Face(((Face)gauss.getFacesList().get(i)).getId(),(Loop)((Face)gauss.getFacesList().get(i)).getLoopList().get(0));
			Vertex vertexAuxGauss = (Vertex)gauss.getVerticesFace(faceGauss).get(gauss.getVerticesFace(faceGauss).size()-1);
			IPoint3d pGauss = new IPoint3d( new Double(f.format(((Vertex)vertexAuxGauss).getCoords().x))
					,new Double(f.format(((Vertex)vertexAuxGauss).getCoords().y))
					,new Double(f.format(((Vertex)vertexAuxGauss).getCoords().z)));
			Vertex vgauss = new Vertex(vertexAuxGauss.getId(),pGauss);
			vgauss.setValues(((Vertex)vertexAuxGauss).getValues());
			vertices.add(vgauss);
			
			//adding the others vertices of the gauss mesh
			Face face =  (Face)gauss.getFacesList().get(i);
			for (int j = 0; j < gauss.getVerticesFace(face).size()-1; j++) {
				LinkedList aux = new LinkedList();
				aux = fem.getVerticesFace(face);
				IPoint3d p = new IPoint3d( new Double(f.format(((Vertex)aux.get(j)).getCoords().x))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().y))
						,new Double(f.format(((Vertex)aux.get(j)).getCoords().z)));
				Vertex v = new Vertex(((Vertex)aux.get(j)).getId(),p);
				v.setValues(((Vertex)aux.get(j)).getValues());
				vertices.add(v);
			}
			Delaunay del = new Delaunay(vertices);
			del.compute();
			trianglesHalfEdgesList.add(del.fillHalfEdge());
		}
	}
	
//	**************************************************************************************
	
	public void add(Object obj){
		
	}
	
//	**************************************************************************************
	
	public boolean containsControl(Point2D po){
		return false;
	}
	
//	**************************************************************************************   
	
	public void remove(Object obj){
	}
	
//	**************************************************************************************
	
	public List removeSelection(){
		return null;
	}
	
//	**************************************************************************************
	
	public void removeAll(){
	}
	
//	**************************************************************************************
	
	public boolean contains(Point2D po){
		return false;
	}
	
//	**************************************************************************************
	
	public boolean contains(Point po){
		return false;
	}
	
//	**************************************************************************************
	
	public boolean contains(IPoint3d po){
		return false;
	}
	
//	**************************************************************************************
	
	public Point pick(Point p){
		return p;
	}
	
//	**************************************************************************************  
	
	public void select(Point p){
		Draw draw;
		int index;
		
		if(((PostpViewState)view.getViewState()).getSelectionViewState().isElementsSelected()){
			ListIterator fcs = facesDraw.listIterator();
			while(fcs.hasNext()) {
				draw = (Draw)fcs.next();
				if (draw.contains(p)) {	
					if (draw.isSelected()) {
						draw.setSelected(false);
						index = selections.indexOf(draw.getRepresents());
						selections.remove(index);
						return;
					}else{
						draw.setSelected(true);
						selections.add(draw.getRepresents());
						return;
					}
				}
			}
			this.view.getDrawingArea().repaint();
		}
		
		if(((PostpViewState)view.getViewState()).getSelectionViewState().isNodesSelected()){
			ListIterator vtx = vertexDraw.listIterator();
			while(vtx.hasNext()) {
				draw = (Draw)vtx.next();
				if (draw.contains(p)) {	
					if (draw.isSelected()) {
						draw.setSelected(false);
						index = selections.indexOf(draw.getRepresents());
						selections.remove(index);
						return;
					}else{
						draw.setSelected(true);
						selections.add(draw.getRepresents());
						
						
						return;
					}
				}
			}
			this.view.getDrawingArea().repaint();
		}
		
		if(((PostpViewState)view.getViewState()).getSelectionViewState().isGaussSelected()){
			ListIterator gvtx = gaussVertexDraw.listIterator();
			while(gvtx.hasNext()) {
				draw = (Draw)gvtx.next();
				if (draw.contains(p)) { 
					if (draw.isSelected()) {
						draw.setSelected(false);
						index = selections.indexOf(draw.getRepresents());
						selections.remove(index);
						return;
					}else{
						draw.setSelected(true);
						selections.add(draw.getRepresents());
						return;
					}
				}
			}
			this.view.getDrawingArea().repaint();
		}
		
//		if(((PostpViewState)this.view.getViewState()).getMeshStateViewState().isMeshStateOnOff()){
//		if(((PostpViewState)view.getViewState()).getSelectionViewState().isNodesSelected()){
//		ListIterator vtx = deformedVertexDraw.listIterator();
//		while(vtx.hasNext()) {
//		draw = (Draw)vtx.next();
//		if (draw.contains(p)) {	
//		if (draw.isSelected()) {
//		draw.setSelected(false);
//		index = selections.indexOf(draw.getRepresents());
//		selections.remove(index);
//		return;
//		}else{
//		draw.setSelected(true);
//		selections.add(draw.getRepresents());
//		return;
//		}
//		}
//		}
//		this.view.getDrawingArea().repaint();
//		}
//		}
		
	}
	
//	**************************************************************************************
	
	public void selectAll(){
	}
	
//	**************************************************************************************
	
	public void unSelectAll(){
	}
	
//	**************************************************************************************
	
	public ArrayList getSelection(){
		return selections;
	}
	
//	**************************************************************************************
	
	public synchronized void compose(){
		
		meshState = ((PostpViewState)((PostpView)this.view).getViewState()).getMeshStateViewState();
		edgeState = ((PostpViewState)((PostpView)this.view).getViewState()).getEdgeViewState();
		faceState = ((PostpViewState)((PostpView)this.view).getViewState()).getFaceViewState();
		vertexState = ((PostpViewState)((PostpView)this.view).getViewState()).getVertexViewState();
		gaussVertexState = ((PostpViewState)((PostpView)this.view).getViewState()).getGaussVertexViewState();
		
//		Thread t1 = new Thread() {
//		public synchronized void run() {
//		if(vertexState.isVertexOnOff()){
//		composeVerticesDraw(); 
//		}
//		}
//		};
//		t1.start();
		
		if(vertexState.isVertexOnOff()){
			composeVerticesDraw(); 
		}
		if(vertexState.isLoadOnOff()){
			composeNodalLoadsDraw();
		}
		if(vertexState.isRestraintsOnOff()&&meshState.isMeshOnOff()){
			composeRestraintsDraw();
		}
		
		if(gaussVertexState.isGaussPointsOn()){
			composeGaussDraw();
		}
		
		if(meshState.isMeshOnOff()){
			composeFacesDraw();
		}
		
		if(vertexState.isLoadOnOff()){
			composeNodalLoadsDrawOnMeshState();
		}
		if(vertexState.isRestraintsOnOff()&&meshState.isMeshStateOnOff()){
			composeRestraintsDrawOnMeshState();
		}
		
		if(meshState.isMeshStateOnOff()){  
			composeVerticesStateDraw();
			composeFacesStateDraw();
		}
		
	}
	
	private synchronized void composeRestraintsDraw(){
		restraintsDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		Vertex vertex;
		Iterator itr = this.vertices.iterator();
		while ( itr.hasNext()){
			vertex = (Vertex)itr.next();
			// compute the delta value
			IPoint3d aux = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
			Point auxView = view.getDrawingArea().getViewPoint(aux.x,aux.y);
			Point auxView2 = new Point(auxView.x+10,auxView.y+10);
			IPoint3d aux2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxView2));
			double delta = aux2.distance(aux);
			
			boolean Rdx = false;
			boolean Rdy = false;
			boolean Rdz = false; 
			boolean Rrx = false;
			boolean Rry = false;
			boolean Rrz = false;
			
			//adding supports and springs
			if(vertex.getValues().containsKey("RESTRAINTS-Dx")){
				Rdx = (Boolean)vertex.getValue("RESTRAINTS-Dx");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Dy")){
				Rdy = (Boolean)vertex.getValue("RESTRAINTS-Dy");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Dz")){
				Rdz = (Boolean)vertex.getValue("RESTRAINTS-Dz");
			}
			
			if(vertex.getValues().containsKey("RESTRAINTS-Rx")){
				Rrx = (Boolean)vertex.getValue("RESTRAINTS-Rx");
			}
			
			if(vertex.getValues().containsKey("RESTRAINTS-Ry")){
				Rry = (Boolean)vertex.getValue("RESTRAINTS-Ry");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Rz")){
				Rrz = (Boolean)vertex.getValue("RESTRAINTS-Rz");
			}
			
			//Restraints DX
			if (Rdx) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta,vertex.getCoords().y+delta/3,vertex.getCoords().z);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta, vertex.getCoords().y-delta/3,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.X(pd0,pd1,pd2);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
			}
			
			//Restraints DY
			if (Rdy) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x+delta/3,vertex.getCoords().y-delta,vertex.getCoords().z);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta/3, vertex.getCoords().y-delta,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.Y(pd0,pd1,pd2);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
			} 
			
			//Restraints DZ
			if (Rdz) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/2);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/2);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/2);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.Z(pd0,pd1,pd2,pd3,pd4);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
			}
			
//			//Restraints DZRxRy - Clamped
//			if (Rdz&&Rrx&&Rry) { 
//				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
//				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
//				points.add(p0);
//				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
//				points.add(p1);
//				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
//				points.add(p2);
//				IPoint3d p3 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/10);
//				points.add(p3);
//				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/10);
//				points.add(p4);
//				IPoint3d p5 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/7);
//				points.add(p5);
//				IPoint3d p6 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/7);
//				points.add(p6);
//				IPoint3d p7 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/7);
//				points.add(p7);
//				IPoint3d p8 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/7);
//				points.add(p8);
//				IPoint3d p9 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z-delta/10);
//				points.add(p9);
//				
//				Point[] pd = new Point[points.size()];
//				
//				for (int i = 0; i < points.size(); i++) {
//					IPoint3d paux = points.get(i);
//					IMatrix pt = new IMatrix(1,4);
//					pt.setElement(0,0,paux.x);
//					pt.setElement(0,1,paux.y);
//					pt.setElement(0,2,paux.z);
//					pt.setElement(0,3,1);
//					pt.mul(m);
//					double x = pt.getElement(0,0);
//					double y = pt.getElement(0,1);
//					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
//					pd[i] = pdaux;
//					
//				}
//				Draw draw = new RestraintsDraw.XYZ(pd);
//				draw.setRepresents(vertex);
//				restraintsDraw.add(draw);
//			}
//			
			//Restraint RX
			if (Rrx) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/10,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/2);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta/10, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x-delta/10, vertex.getCoords().y+delta/2,vertex.getCoords().z+delta/2);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/10,vertex.getCoords().y-delta/2,vertex.getCoords().z+delta/2);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x-delta/10,vertex.getCoords().y,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RX(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
				
			}
			
			//Restraint RY
			if (Rry) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/10,vertex.getCoords().z-delta/2);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/10,vertex.getCoords().z-delta/2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/10,vertex.getCoords().z+delta/2);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/10,vertex.getCoords().z+delta/2);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x,vertex.getCoords().y-delta/10,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				//double z = pt.getElement(0,2);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RY(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
				
			}
			
			//Restraint RZ
			if (Rrz) { 
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z+delta/10);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z+delta/10);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x,vertex.getCoords().y-delta/10,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RZ(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsDraw.add(draw);
				
			}
			
		}//end loop of vertices
		
		
	}
	
	private synchronized void composeNodalLoadsDraw(){
		nodalLoadsDraw = new ArrayList<Draw>();
		
		IMatrix m = geoTransform.getMatrix();
		Vertex vertex;
		Iterator itr = this.vertices.iterator();
		while ( itr.hasNext()){
			vertex = (Vertex)itr.next();
			
			// compute the delta value
			IPoint3d aux = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
			Point auxView = view.getDrawingArea().getViewPoint(aux.x,aux.y);
			Point auxView2 = new Point(auxView.x+10,auxView.y+10);
			IPoint3d aux2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxView2));
			double delta = aux2.distance(aux);
			
			boolean nLFx = false;
			boolean nLFy = false;
			boolean nLFz = false;
			boolean nLMx = false;
			boolean nLMy = false;
			boolean nLMz = false;
			
			if(vertex.getValues().containsKey("Force-Dx")){
				if(((Double)vertex.getValue("Force-Dx"))!=0.0){
					nLFx = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Dy")){
				if(((Double)vertex.getValue("Force-Dy"))!=0.0){
					nLFy = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Dz")){
				if(((Double)vertex.getValue("Force-Dz"))!=0.0){
					nLFz = true;
				}
			}
			if(vertex.getValues().containsKey("Loads-Dz")){
				if(((Double)vertex.getValue("Loads-Dz"))!=0.0){
					nLFz = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Mx")){
				if(((Double)vertex.getValue("Force-Mx"))!=0.0){
					nLMx = true;
				}
			}
			if(vertex.getValues().containsKey("Loads-Mx")){
				if(((Double)vertex.getValue("Loads-Mx"))!=0.0){
					nLMx = true;
				}
			}
			if(vertex.getValues().containsKey("Force-My")){
				if(((Double)vertex.getValue("Force-My"))!=0.0){
					nLMy = true;
				}
			}
			if(vertex.getValues().containsKey("Loads-My")){
				if(((Double)vertex.getValue("Loads-My"))!=0.0){
					nLMy = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Mz")){
				if(((Double)vertex.getValue("Force-Mz"))!=0.0){
					nLMz = true;
				}
			}
			if(vertex.getValues().containsKey("Loads-Mz")){
				if(((Double)vertex.getValue("Loads-Mz"))!=0.0){
					nLMz = true;
				}
			}
			
			if (nLFx) { 
				if(((Double)vertex.getValue("Force-Dx"))>0){
					ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
					IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p0);
					IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/3,vertex.getCoords().y-delta/10,vertex.getCoords().z);
					points.add(p1);
					IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta/3, vertex.getCoords().y+delta/10,vertex.getCoords().z);
					points.add(p2);
					IPoint3d p3 = new IPoint3d(vertex.getCoords().x-2*delta, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p3);
					
					Point[] pd = new Point[points.size()];
					
					for (int i = 0; i < points.size(); i++) {
						IPoint3d paux = points.get(i);
						IMatrix pt = new IMatrix(1,4);
						pt.setElement(0,0,paux.x);
						pt.setElement(0,1,paux.y);
						pt.setElement(0,2,paux.z);
						pt.setElement(0,3,1);
						pt.mul(m);
						double x = pt.getElement(0,0);
						double y = pt.getElement(0,1);
						Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
						pd[i] = pdaux;
					}
					Draw draw = new NodalLoadDraw.X(pd[0],pd[1],pd[2], pd[3]);
					draw.setRepresents(vertex);
					nodalLoadsDraw.add(draw);
					
				}else if(((Double)vertex.getValue("Force-Dx"))<0){
					ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
					IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p0);
					IPoint3d p1 = new IPoint3d(vertex.getCoords().x+2*delta/3,vertex.getCoords().y-2*delta/10,vertex.getCoords().z);
					points.add(p1);
					IPoint3d p2 = new IPoint3d(vertex.getCoords().x+2*delta/3, vertex.getCoords().y+2*delta/10,vertex.getCoords().z);
					points.add(p2);
					IPoint3d p3 = new IPoint3d(vertex.getCoords().x+4*delta, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p3);
					
					Point[] pd = new Point[points.size()];
					
					for (int i = 0; i < points.size(); i++) {
						IPoint3d paux = points.get(i);
						IMatrix pt = new IMatrix(1,4);
						pt.setElement(0,0,paux.x);
						pt.setElement(0,1,paux.y);
						pt.setElement(0,2,paux.z);
						pt.setElement(0,3,1);
						pt.mul(m);
						double x = pt.getElement(0,0);
						double y = pt.getElement(0,1);
						Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
						pd[i] = pdaux;
					}
					Draw draw = new NodalLoadDraw.X(pd[0],pd[1],pd[2], pd[3]);
					draw.setRepresents(vertex);
					nodalLoadsDraw.add(draw);
				}
			}
			
			if (nLFy) { 
				if(((Double)vertex.getValue("Force-Dy"))<0){
					ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
					IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p0);
					IPoint3d p1 = new IPoint3d(vertex.getCoords().x-2*delta/10,vertex.getCoords().y+2*delta/3,vertex.getCoords().z);
					points.add(p1);
					IPoint3d p2 = new IPoint3d(vertex.getCoords().x+2*delta/10, vertex.getCoords().y+2*delta/3,vertex.getCoords().z);
					points.add(p2);
					IPoint3d p3 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y+4*delta,vertex.getCoords().z);
					points.add(p3);
					
					Point[] pd = new Point[points.size()];
					
					for (int i = 0; i < points.size(); i++) {
						IPoint3d paux = points.get(i);
						IMatrix pt = new IMatrix(1,4);
						pt.setElement(0,0,paux.x);
						pt.setElement(0,1,paux.y);
						pt.setElement(0,2,paux.z);
						pt.setElement(0,3,1);
						pt.mul(m);
						double x = pt.getElement(0,0);
						double y = pt.getElement(0,1);
						Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
						pd[i] = pdaux;
					}
					Draw draw = new NodalLoadDraw.Y(pd[0],pd[1],pd[2], pd[3]);
					draw.setRepresents(vertex);
					nodalLoadsDraw.add(draw);
					
				}else if(((Double)vertex.getValue("Force-Dy"))>0){
					ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
					IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y+4*delta,vertex.getCoords().z);
					points.add(p0);
					IPoint3d p1 = new IPoint3d(vertex.getCoords().x-2*delta/10,vertex.getCoords().y+2*delta/3,vertex.getCoords().z);
					points.add(p1);
					IPoint3d p2 = new IPoint3d(vertex.getCoords().x+2*delta/10, vertex.getCoords().y+2*delta/3,vertex.getCoords().z);
					points.add(p2);
					IPoint3d p3 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
					points.add(p3);
					
					Point[] pd = new Point[points.size()];
					
					for (int i = 0; i < points.size(); i++) {
						IPoint3d paux = points.get(i);
						IMatrix pt = new IMatrix(1,4);
						pt.setElement(0,0,paux.x);
						pt.setElement(0,1,paux.y);
						pt.setElement(0,2,paux.z);
						pt.setElement(0,3,1);
						pt.mul(m);
						double x = pt.getElement(0,0);
						double y = pt.getElement(0,1);
						Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
						pd[i] = pdaux;
					}
					Draw draw = new NodalLoadDraw.Y(pd[0],pd[1],pd[2], pd[3]);
					draw.setRepresents(vertex);
					nodalLoadsDraw.add(draw);
				}
			}
			if (nLFz) { 
				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p0);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x+delta/10,vertex.getCoords().y+delta/10,vertex.getCoords().z+delta/5);
				points.add(p1);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta/10, vertex.getCoords().y-delta/10,vertex.getCoords().z+delta/5);
				points.add(p2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z+delta);
				points.add(p3);
				
				Point[] pd = new Point[points.size()];
				for (int i = 0; i < points.size(); i++) {
					IPoint3d paux = points.get(i);
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,paux.x);
					pt.setElement(0,1,paux.y);
					pt.setElement(0,2,paux.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double x = pt.getElement(0,0);
					double y = pt.getElement(0,1);
					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
					pd[i] = pdaux;
				}
				Draw draw = new NodalLoadDraw.Z(pd[0],pd[1],pd[2], pd[3]);
				draw.setRepresents(vertex);
				nodalLoadsDraw.add(draw);
			}
			
			if (nLMx) { 
				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p0);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/3,vertex.getCoords().y-delta/10,vertex.getCoords().z);
				points.add(p1);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x-delta/3, vertex.getCoords().y+delta/10,vertex.getCoords().z);
				points.add(p2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x-delta/3, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p3);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-2*delta/3, vertex.getCoords().y-delta/10,vertex.getCoords().z);
				points.add(p4);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x-2*delta/3, vertex.getCoords().y+delta/10,vertex.getCoords().z);
				points.add(p5);
				IPoint3d p6 = new IPoint3d(vertex.getCoords().x-delta, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p6);
				
				Point[] pd = new Point[points.size()];
				
				for (int i = 0; i < points.size(); i++) {
					IPoint3d paux = points.get(i);
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,paux.x);
					pt.setElement(0,1,paux.y);
					pt.setElement(0,2,paux.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double x = pt.getElement(0,0);
					double y = pt.getElement(0,1);
					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
					pd[i] = pdaux;
				}
				Draw draw = new NodalLoadDraw.MX(pd);
				draw.setRepresents(vertex);
				nodalLoadsDraw.add(draw);
			}
			
			if (nLMy) { 
				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p0);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/10,vertex.getCoords().y-delta/3,vertex.getCoords().z);
				points.add(p1);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/10, vertex.getCoords().y-delta/3,vertex.getCoords().z);
				points.add(p2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y-delta/3,vertex.getCoords().z);
				points.add(p3);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/10, vertex.getCoords().y-2*delta/3,vertex.getCoords().z);
				points.add(p4);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x+delta/10, vertex.getCoords().y-2*delta/3,vertex.getCoords().z);
				points.add(p5);
				IPoint3d p6 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y-delta,vertex.getCoords().z);
				points.add(p6);
				
				Point[] pd = new Point[points.size()];
				
				for (int i = 0; i < points.size(); i++) {
					IPoint3d paux = points.get(i);
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,paux.x);
					pt.setElement(0,1,paux.y);
					pt.setElement(0,2,paux.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double x = pt.getElement(0,0);
					double y = pt.getElement(0,1);
					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
					pd[i] = pdaux;
				}
				Draw draw = new NodalLoadDraw.MX(pd);
				draw.setRepresents(vertex);
				nodalLoadsDraw.add(draw);
			}
			
			if (nLMz) { 
				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
				points.add(p0);
				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/10,vertex.getCoords().y,vertex.getCoords().z+delta/3);
				points.add(p1);
				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/10, vertex.getCoords().y,vertex.getCoords().z+delta/3);
				points.add(p2);
				IPoint3d p3 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z+delta/3);
				points.add(p3);
				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/10, vertex.getCoords().y,vertex.getCoords().z+2*delta/3);
				points.add(p4);
				IPoint3d p5 = new IPoint3d(vertex.getCoords().x+delta/10, vertex.getCoords().y,vertex.getCoords().z+2*delta/3);
				points.add(p5);
				IPoint3d p6 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z+delta);
				points.add(p6);
				
				Point[] pd = new Point[points.size()];
				
				for (int i = 0; i < points.size(); i++) {
					IPoint3d paux = points.get(i);
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,paux.x);
					pt.setElement(0,1,paux.y);
					pt.setElement(0,2,paux.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double x = pt.getElement(0,0);
					double y = pt.getElement(0,1);
					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
					pd[i] = pdaux;
				}
				Draw draw = new NodalLoadDraw.MX(pd);
				draw.setRepresents(vertex);
				nodalLoadsDraw.add(draw);
			}
			
			
			
		}//end loop vertices
	}
	
	private synchronized void composeRestraintsDrawOnMeshState(){
		
		restraintsOnMeshStateDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		Vertex vertex;
		Iterator itr = this.vertices.iterator();
		while ( itr.hasNext()){
			vertex = (Vertex)itr.next();
			// compute the delta value
			IPoint3d aux = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
			Point auxView = view.getDrawingArea().getViewPoint(aux.x,aux.y);
			Point auxView2 = new Point(auxView.x+10,auxView.y+10);
			IPoint3d aux2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxView2));
			double delta = aux2.distance(aux);
			
			boolean Rdx = false;
			boolean Rdy = false;
			boolean Rdz = false; 
			boolean Rrx = false;
			boolean Rry = false;
			boolean Rrz = false;
			
			//adding supports and springs
			if(vertex.getValues().containsKey("RESTRAINTS-Dx")){
				Rdx = (Boolean)vertex.getValue("RESTRAINTS-Dx");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Dy")){
				Rdy = (Boolean)vertex.getValue("RESTRAINTS-Dy");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Dz")){
				Rdz = (Boolean)vertex.getValue("RESTRAINTS-Dz");
			}
			
			if(vertex.getValues().containsKey("RESTRAINTS-Rx")){
				Rrx = (Boolean)vertex.getValue("RESTRAINTS-Rx");
			}
			
			if(vertex.getValues().containsKey("RESTRAINTS-Ry")){
				Rry = (Boolean)vertex.getValue("RESTRAINTS-Ry");
			}
			if(vertex.getValues().containsKey("RESTRAINTS-Rz")){
				Rrz = (Boolean)vertex.getValue("RESTRAINTS-Rz");
			}
			
			double xv = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
			double yv = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
			double zv = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
			
			//Restraints DX
			if (Rdx) { 
				IPoint3d p0 = new IPoint3d(xv, yv,zv);
				IPoint3d p1 = new IPoint3d(xv-delta,yv+delta/3,zv);
				IPoint3d p2 = new IPoint3d(xv-delta, yv-delta/3,zv);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.X(pd0,pd1,pd2);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
			}
			
			//Restraints DY
			if (Rdy) { 
				IPoint3d p0 = new IPoint3d(xv, yv,zv);
				IPoint3d p1 = new IPoint3d(xv+delta/3,yv-delta,zv);
				IPoint3d p2 = new IPoint3d(xv-delta/3, yv-delta,zv);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.Y(pd0,pd1,pd2);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
			} 
			
			//Restraints DZ
			if (Rdz) { 
				IPoint3d p0 = new IPoint3d(xv, yv,vertex.getCoords().z);
				IPoint3d p1 = new IPoint3d(xv-delta/2,yv-delta/2,zv-delta/2);
				IPoint3d p2 = new IPoint3d(xv+delta/2, yv-delta/2,zv-delta/2);
				IPoint3d p3 = new IPoint3d(xv+delta/2, yv+delta/2,zv-delta/2);
				IPoint3d p4 = new IPoint3d(xv-delta/2,yv+delta/2,zv-delta/2);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.Z(pd0,pd1,pd2,pd3,pd4);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
			}
			
//			//Restraints DZRxRy - Clamped
//			if (Rdz&&Rrx&&Rry) { 
//				ArrayList<IPoint3d> points = new ArrayList<IPoint3d>();
//				IPoint3d p0 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
//				points.add(p0);
//				IPoint3d p1 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
//				points.add(p1);
//				IPoint3d p2 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/10);
//				points.add(p2);
//				IPoint3d p3 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/10);
//				points.add(p3);
//				IPoint3d p4 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/10);
//				points.add(p4);
//				IPoint3d p5 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/7);
//				points.add(p5);
//				IPoint3d p6 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y-delta/2,vertex.getCoords().z-delta/7);
//				points.add(p6);
//				IPoint3d p7 = new IPoint3d(vertex.getCoords().x+delta/2, vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/7);
//				points.add(p7);
//				IPoint3d p8 = new IPoint3d(vertex.getCoords().x-delta/2,vertex.getCoords().y+delta/2,vertex.getCoords().z-delta/7);
//				points.add(p8);
//				IPoint3d p9 = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z-delta/10);
//				points.add(p9);
//				
//				Point[] pd = new Point[points.size()];
//				
//				for (int i = 0; i < points.size(); i++) {
//					IPoint3d paux = points.get(i);
//					IMatrix pt = new IMatrix(1,4);
//					pt.setElement(0,0,paux.x);
//					pt.setElement(0,1,paux.y);
//					pt.setElement(0,2,paux.z);
//					pt.setElement(0,3,1);
//					pt.mul(m);
//					double x = pt.getElement(0,0);
//					double y = pt.getElement(0,1);
//					Point pdaux = new Point(view.getDrawingArea().getViewPoint(x,y));
//					pd[i] = pdaux;
//					
//				}
//				Draw draw = new RestraintsDraw.XYZ(pd);
//				draw.setRepresents(vertex);
//				restraintsOnMeshStateDraw.add(draw);
//			}
//			
			//Restraint RX
			if (Rrx) { 
				IPoint3d p0 = new IPoint3d(xv, yv,zv);
				IPoint3d p1 = new IPoint3d(xv-delta/10,yv-delta/2,zv-delta/2);
				IPoint3d p2 = new IPoint3d(xv-delta/10,yv+delta/2,zv-delta/2);
				IPoint3d p3 = new IPoint3d(xv-delta/10,yv+delta/2,zv+delta/2);
				IPoint3d p4 = new IPoint3d(xv-delta/10,yv-delta/2,zv+delta/2);
				IPoint3d p5 = new IPoint3d(xv-delta/10,yv,zv);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RX(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
				
			}
			
			//Restraint RY
			if (Rry) { 
				IPoint3d p0 = new IPoint3d(xv,yv,zv);
				IPoint3d p1 = new IPoint3d(xv-delta/2,yv-delta/10,zv-delta/2);
				IPoint3d p2 = new IPoint3d(xv+delta/2,yv-delta/10,zv-delta/2);
				IPoint3d p3 = new IPoint3d(xv+delta/2,yv-delta/10,zv+delta/2);
				IPoint3d p4 = new IPoint3d(xv-delta/2,yv-delta/10,zv+delta/2);
				IPoint3d p5 = new IPoint3d(xv,yv-delta/10,zv);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				//double z = pt.getElement(0,2);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				//z = pt.getElement(0,2);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RY(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
				
			}
			
			//Restraint RZ
			if (Rrz) { 
				IPoint3d p0 = new IPoint3d(xv,yv,zv);
				IPoint3d p1 = new IPoint3d(xv-delta/2,yv-delta/2,zv-delta/10);
				IPoint3d p2 = new IPoint3d(xv+delta/2,yv-delta/2,zv-delta/10);
				IPoint3d p3 = new IPoint3d(xv+delta/2,yv+delta/2,zv+delta/10);
				IPoint3d p4 = new IPoint3d(xv-delta/2,yv+delta/2,zv+delta/10);
				IPoint3d p5 = new IPoint3d(xv,yv-delta/10,zv);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p4.x);
				pt.setElement(0,1,p4.y);
				pt.setElement(0,2,p4.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p5.x);
				pt.setElement(0,1,p5.y);
				pt.setElement(0,2,p5.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				x = pt.getElement(0,0);
				y = pt.getElement(0,1);
				Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
				
				Draw draw = new RestraintsDraw.RZ(pd0,pd1,pd2,pd3,pd4,pd5);
				draw.setRepresents(vertex);
				restraintsOnMeshStateDraw.add(draw);
			}
		
		}//end loop of vertices
	}
	
	private synchronized void composeNodalLoadsDrawOnMeshState(){
		nodalLoadsOnMeshStateDraw = new ArrayList<Draw>();
		
		IMatrix m = geoTransform.getMatrix();
		Vertex vertex;
		Iterator itr = this.vertices.iterator();
		while ( itr.hasNext()){
			vertex = (Vertex)itr.next();
			
			// compute the delta value
			IPoint3d aux = new IPoint3d(vertex.getCoords().x, vertex.getCoords().y,vertex.getCoords().z);
			Point auxView = view.getDrawingArea().getViewPoint(aux.x,aux.y);
			Point auxView2 = new Point(auxView.x+10,auxView.y+10);
			IPoint3d aux2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxView2));
			double delta = aux2.distance(aux);
			
			boolean nLFx = false;
			boolean nLFy = false;
			boolean nLFz = false;
			boolean nLMx = false;
			//	boolean nLMy = false;
			//	boolean nLMz = false;
			
			if(vertex.getValues().containsKey("Force-Dx")){
				if(((Double)vertex.getValue("Force-Dx"))!=0.0){
					nLFx = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Dy")){
				if(((Double)vertex.getValue("Force-Dy"))!=0.0){
					nLFy = true;
				}
			}
			if(vertex.getValues().containsKey("Force-Dz")){
				if(((Double)vertex.getValue("Force-Dz"))!=0.0){
					nLFz = true;
				}
			}
			
			if (nLFx) { 
				if(((Double)vertex.getValue("Force-Dx"))>0){
					double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
					double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
					double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
					
					IPoint3d p0 = new IPoint3d(x,y,z);
					IPoint3d p1 = new IPoint3d(x-2*delta/3,y-2*delta/10,z);
					IPoint3d p2 = new IPoint3d(x-2*delta/3,y+2*delta/10,z);
					IPoint3d p3 = new IPoint3d(x-4*delta,y,z);
					
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,p0.x);
					pt.setElement(0,1,p0.y);
					pt.setElement(0,2,p0.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double xd = pt.getElement(0,0);
					double yd = pt.getElement(0,1);
					//double z = pt.getElement(0,2);
					Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p1.x);
					pt.setElement(0,1,p1.y);
					pt.setElement(0,2,p1.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p2.x);
					pt.setElement(0,1,p2.y);
					pt.setElement(0,2,p2.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p3.x);
					pt.setElement(0,1,p3.y);
					pt.setElement(0,2,p3.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
					draw.setRepresents(vertex);
					nodalLoadsOnMeshStateDraw.add(draw);
					
				}else if(((Double)vertex.getValue("Force-Dx"))<0){
					double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
					double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
					double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
					
					IPoint3d p0 = new IPoint3d(x,y,z);
					IPoint3d p1 = new IPoint3d(x+2*delta/3,y-2*delta/10,z);
					IPoint3d p2 = new IPoint3d(x+2*delta/3,y+2*delta/10,z);
					IPoint3d p3 = new IPoint3d(x+4*delta,y,z);
					
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,p0.x);
					pt.setElement(0,1,p0.y);
					pt.setElement(0,2,p0.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double xd = pt.getElement(0,0);
					double yd = pt.getElement(0,1);
					//double z = pt.getElement(0,2);
					Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p1.x);
					pt.setElement(0,1,p1.y);
					pt.setElement(0,2,p1.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p2.x);
					pt.setElement(0,1,p2.y);
					pt.setElement(0,2,p2.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p3.x);
					pt.setElement(0,1,p3.y);
					pt.setElement(0,2,p3.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					//z = pt.getElement(0,2);
					Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
					draw.setRepresents(vertex);
					nodalLoadsOnMeshStateDraw.add(draw);
					
				}
			}
			
			if (nLFy) { 
				if(((Double)vertex.getValue("Force-Dy"))<0){
					double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
					double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
					double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
					
					IPoint3d p0 = new IPoint3d(x,y,z);
					IPoint3d p1 = new IPoint3d(x-2*delta/10,y+2*delta/3,z);
					IPoint3d p2 = new IPoint3d(x+2*delta/10,y+2*delta/3,z);
					IPoint3d p3 = new IPoint3d(x,y+4*delta,z);
					
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,p0.x);
					pt.setElement(0,1,p0.y);
					pt.setElement(0,2,p0.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double xd = pt.getElement(0,0);
					double yd = pt.getElement(0,1);
					Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p1.x);
					pt.setElement(0,1,p1.y);
					pt.setElement(0,2,p1.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p2.x);
					pt.setElement(0,1,p2.y);
					pt.setElement(0,2,p2.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p3.x);
					pt.setElement(0,1,p3.y);
					pt.setElement(0,2,p3.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
					draw.setRepresents(vertex);
					nodalLoadsOnMeshStateDraw.add(draw);
					
				}else if(((Double)vertex.getValue("Force-Dy"))>0){
					double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
					double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
					double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
					
					IPoint3d p0 = new IPoint3d(x,y+4*delta,z);
					IPoint3d p1 = new IPoint3d(x-2*delta/10,y+2*delta/3,z);
					IPoint3d p2 = new IPoint3d(x+2*delta/10,y+2*delta/3,z);
					IPoint3d p3 = new IPoint3d(x,y,z);
					
					IMatrix pt = new IMatrix(1,4);
					pt.setElement(0,0,p0.x);
					pt.setElement(0,1,p0.y);
					pt.setElement(0,2,p0.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					double xd = pt.getElement(0,0);
					double yd = pt.getElement(0,1);
					Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p1.x);
					pt.setElement(0,1,p1.y);
					pt.setElement(0,2,p1.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p2.x);
					pt.setElement(0,1,p2.y);
					pt.setElement(0,2,p2.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					pt = new IMatrix(1,4);
					pt.setElement(0,0,p3.x);
					pt.setElement(0,1,p3.y);
					pt.setElement(0,2,p3.z);
					pt.setElement(0,3,1);
					pt.mul(m);
					xd = pt.getElement(0,0);
					yd = pt.getElement(0,1);
					Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
					
					Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
					draw.setRepresents(vertex);
					nodalLoadsOnMeshStateDraw.add(draw);
				}
			}
			if (nLFz) { 
				double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
				double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
				double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
				
				IPoint3d p0 = new IPoint3d(x,y,z);
				IPoint3d p1 = new IPoint3d(x+delta/10,y+delta/10,z+delta/5);
				IPoint3d p2 = new IPoint3d(x-delta/10,y-delta/10,z+delta/5);
				IPoint3d p3 = new IPoint3d(x,y,vertex.getCoords().z+delta);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double xd = pt.getElement(0,0);
				double yd = pt.getElement(0,1);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
				draw.setRepresents(vertex);
				nodalLoadsOnMeshStateDraw.add(draw);
				
			}
			if (nLMx) { 
				double x = vertex.getCoords().x + ((Double)vertex.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
				double y = vertex.getCoords().y + ((Double)vertex.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
				double z = vertex.getCoords().z + ((Double)vertex.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
				
				IPoint3d p0 = new IPoint3d(x,y,z);
				IPoint3d p1 = new IPoint3d(x-delta/5,y-delta/10,z);
				IPoint3d p2 = new IPoint3d(x-delta/5,y+delta/10,z);
				IPoint3d p3 = new IPoint3d(x-2*delta,y,z);
				
				//IPoint3d p4 = new IPoint3d(vertex.getCoords().x,vertex.getCoords().y,vertex.getCoords().z);
				//IPoint3d p5 = new IPoint3d(vertex.getCoords().x-delta/5, vertex.getCoords().y+delta/10,vertex.getCoords().z);
				//IPoint3d p6 = new IPoint3d(vertex.getCoords().x-2*delta, vertex.getCoords().y,vertex.getCoords().z);
				
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,p0.x);
				pt.setElement(0,1,p0.y);
				pt.setElement(0,2,p0.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				double xd = pt.getElement(0,0);
				double yd = pt.getElement(0,1);
				//double z = pt.getElement(0,2);
				Point pd0 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p1.x);
				pt.setElement(0,1,p1.y);
				pt.setElement(0,2,p1.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd1 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p2.x);
				pt.setElement(0,1,p2.y);
				pt.setElement(0,2,p2.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd2 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				pt = new IMatrix(1,4);
				pt.setElement(0,0,p3.x);
				pt.setElement(0,1,p3.y);
				pt.setElement(0,2,p3.z);
				pt.setElement(0,3,1);
				pt.mul(m);
				xd = pt.getElement(0,0);
				yd = pt.getElement(0,1);
				Point pd3 = new Point(view.getDrawingArea().getViewPoint(xd,yd));
				
				Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
				draw.setRepresents(vertex);
				nodalLoadsOnMeshStateDraw.add(draw);
				
			}
		}
	}
	
	private synchronized void composeVerticesDraw(){
		vertexDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		for(int i=0;i<this.vertices.size();i++){
			IMatrix pt = new IMatrix(1,4);
			pt.setElement(0,0,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).x);
			pt.setElement(0,1,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).y);
			pt.setElement(0,2,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).z);
			pt.setElement(0,3,1);
			pt.mul(m);
			
			double x = pt.getElement(0,0);
			double y = pt.getElement(0,1);
			//double z = pt.getElement(0,2);
			MarkDraw point = new  MarkDraw (((PostpView)this.view).getDrawingArea().getViewPoint(x,y)
					,"POINT",3,(byte)1,(byte)10,this.vertices.get(i));
			point.setRepresents(this.vertices.get(i));
			vertexDraw.add(point);
		}
	}
	
	private synchronized void composeFacesDraw(){
		facesDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		for(int k=0;k<this.faces.size();k++){
			LinkedList verticesList = this.modelFemMesh.getVerticesFace((Face)this.faces.get(k));
			ArrayList<Point> facePoints = new ArrayList<Point>();
			for(int j=0;j<verticesList.size();j++){
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,((Vertex)verticesList.get(j)).getCoords().x);
				pt.setElement(0,1,((Vertex)verticesList.get(j)).getCoords().y);
				pt.setElement(0,2,((Vertex)verticesList.get(j)).getCoords().z);
				pt.setElement(0,3,1);
				pt.mul(m);
				
				double x = pt.getElement(0,0);
				double y = pt.getElement(0,1);
				//double z = pt.getElement(0,2);
				
				facePoints.add(new Point(((PostpView)this.view).getDrawingArea().getViewPoint(x,y).x,
						((PostpView)this.view).getDrawingArea().getViewPoint(x,y).y));
			}
			FaceDraw face = new FaceDraw(facePoints,faces.get(k));
			this.facesDraw.add(face);
		}
	}
	
	private synchronized void composeGaussDraw(){
		gaussVertexDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		//Creating the Gauss vertices draws
		for(int i=0;i<this.gaussVertex.size();i++){
			double x = ((Vertex)this.gaussVertex.get(i)).getCoords().x;
			double y = ((Vertex)this.gaussVertex.get(i)).getCoords().y;
			double z = ((Vertex)this.gaussVertex.get(i)).getCoords().z;
			IMatrix pt = new IMatrix(1,4);
			pt.setElement(0,0,x);
			pt.setElement(0,1,y);
			pt.setElement(0,2,z);
			pt.setElement(0,3,1);
			pt.mul(m);
			
			MarkDraw gaussMark = new  MarkDraw (((PostpView)this.view).getDrawingArea().getViewPoint(pt.getElement(0,0),pt.getElement(0,1)),
					"TIMES",7,(byte)1,(byte)gaussVertexState.getMarkType(),this.gaussVertex.get(i));
			gaussMark.setRepresents(this.gaussVertex.get(i));
			gaussVertexDraw.add(gaussMark);
		}
	}
	
	private synchronized void composeVerticesStateDraw(){
		deformedVertexDraw = new ArrayList<Draw>();
		IMatrix m = geoTransform.getMatrix();
		//Creating the deformed vertices draws  
		for(int i=0;i<this.vertices.size();i++){
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getXKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getXKey(),new Double(0));
			}
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getYKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getYKey(),new Double(0));
			}
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getZKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getZKey(),new Double(0));
			}
			
			double x = ((Vertex)this.vertices.get(i)).getCoords().x + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
			double y = ((Vertex)this.vertices.get(i)).getCoords().y + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
			double z = ((Vertex)this.vertices.get(i)).getCoords().z + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
			
			IMatrix pt = new IMatrix(1,4);
			pt.setElement(0,0,x);
			pt.setElement(0,1,y);
			pt.setElement(0,2,z);
			pt.setElement(0,3,1);
			pt.mul(m);
			
			MarkDraw point = new  MarkDraw (((PostpView)this.view).getDrawingArea().getViewPoint(pt.getElement(0,0),pt.getElement(0,1)),
					"POINT",3,(byte)1,(byte)10);
			
			deformedVertexDraw.add(point);
		}
		
	}
	
	private synchronized void composeFacesStateDraw(){
		deformedFacesDraw = new ArrayList<Draw>();
		//creating the deformed faces draws
		
		for(int k=0;k<this.faces.size();k++){
			LinkedList verticesList = this.modelFemMesh.getVerticesFace((Face)this.faces.get(k));
			ArrayList<Point> deformedFacePoints = new ArrayList<Point>();
			//deformedFacePoints.clear();
			for(int j=0;j<verticesList.size();j++){
				if(((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getXKey()))==null){
					(((Vertex)verticesList.get(j))).setValue((String)meshState.getXKey(),new Double(0));
				}
				if(((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getYKey()))==null){
					(((Vertex)verticesList.get(j))).setValue((String)meshState.getYKey(),new Double(0));
				}
				if(((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getZKey()))==null){
					(((Vertex)verticesList.get(j))).setValue((String)meshState.getZKey(),new Double(0));
				}
				
				double x = ((Vertex)verticesList.get(j)).getCoords().x + ((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
				double y = ((Vertex)verticesList.get(j)).getCoords().y + ((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
				double z = ((Vertex)verticesList.get(j)).getCoords().z + ((Double)(((Vertex)verticesList.get(j))).getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
				
				IMatrix m = geoTransform.getMatrix();
				IMatrix pt = new IMatrix(1,4);
				pt.setElement(0,0,x);
				pt.setElement(0,1,y);
				pt.setElement(0,2,z);
				pt.setElement(0,3,1);
				pt.mul(m);
				
				deformedFacePoints.add(new Point(((PostpView)this.view).getDrawingArea().getViewPoint(pt.getElement(0,0),pt.getElement(0,1)).x,
						((PostpView)this.view).getDrawingArea().getViewPoint(pt.getElement(0,0),pt.getElement(0,1)).y));
			}
			FaceDraw faceDeformed = new FaceDraw(deformedFacePoints,faces.get(k));
			this.deformedFacesDraw.add(faceDeformed);
		}
		
	}
	
	private synchronized void computeDeformedHalfEdge(){
		modelFemMeshState = this.modelFemMesh;
		LinkedList<Vertex> vertices = new LinkedList<Vertex>();
		
		for (int i = 0; i < this.vertices.size(); i++) {
			Vertex v = (Vertex)this.vertices.get(i);
			
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getXKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getXKey(),new Double(0));
			}
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getYKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getYKey(),new Double(0));
			}
			if(((Double)(((Vertex)this.vertices.get(i))).getValue((String)meshState.getZKey()))==null){
				(((Vertex)this.vertices.get(i))).setValue((String)meshState.getZKey(),new Double(0));
			}
			
			double x = ((Vertex)this.vertices.get(i)).getCoords().x + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
			double y = ((Vertex)this.vertices.get(i)).getCoords().y + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
			double z = ((Vertex)this.vertices.get(i)).getCoords().z + ((Double)((Vertex)this.vertices.get(i)).getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
			
			
			IPoint3d p = new IPoint3d(x,y,z);
			
			Vertex newVertex = new Vertex(v.getId(),p);
			
			for (int j = 0; j < v.getKeys().size(); j++) {
				String key = (String)v.getKeys().get(j);
				newVertex.setValue(key,v.getValue(key));
			}
			
			vertices.add(newVertex);
			
		}
		
		modelFemMeshState.setVerticesList(vertices);
		modelFemMeshState.setFacesList(this.faces);
		modelFemMeshState.setEdgesList(this.edges);
		modelFemMeshState.initModel("");
	}
	
//	**************************************************************************************
	
	public Object get(Point2D po){
		return null;
	}
	
//	**************************************************************************************    
	
	public String getPointData(Point po){
		return null;
	}
	
//	**************************************************************************************
	
	public Object get(){
		return null;
	}
	
//	**************************************************************************************
	/** 
	 * The method check if the draw is selected
	 * @return true if there is any selected draw in the list.
	 * @return false if there is no selected draw in the list.
	 */
	public boolean isSelected(){
		Draw draw;
		
		ListIterator vtx = vertexDraw.listIterator();
		while(vtx.hasNext()) {
			draw = (MarkDraw)vtx.next();
			if (draw.isSelected()) {
				return true;
			}
		}
		
		ListIterator gvtx = gaussVertexDraw.listIterator();
		while(gvtx.hasNext()) {
			draw = (MarkDraw)gvtx.next();
			if (draw.isSelected()) {
				return true;
			}
		}
		
		ListIterator vtxD = deformedVertexDraw.listIterator();
		while(vtxD.hasNext()) {
			draw = (MarkDraw)vtxD.next();
			if (draw.isSelected()) {
				return true;
			}
		}
		
		return false;
		
	}
	
//	******************************************************************************************
	
	public synchronized void fit(){
		// Calculating bounds
		if(view.getViewState().isDistort()){
			Rectangle2D.Double limits = findMinMax();
			limits.x = limits.x-0.35*limits.getWidth();
			limits.y = limits.y-0.35*limits.getHeight();
			limits.width =  1.35*limits.width;
			limits.height = 1.35*limits.height;
			((PostpView)this.view).getViewState().setLimits(limits);
			((PostpView)this.view).getDrawingArea().setZoom(limits);
		}else {
			Rectangle2D.Double limits = findMinMax();
			limits.x = limits.x-0.35*limits.getWidth();
			limits.y = limits.y-0.35*limits.getHeight();
			limits.width =  1.35*limits.width;
			limits.height = 1.35*limits.height;
			((PostpView)this.view).getViewState().setLimits(limits);
			((PostpView)this.view).getDrawingArea().setZoom(limits);
		}
		
	}
	
//	************************************************************************************** 
	
	/** 
	 * The method find the max and minimum to x and y coordinates of the draw's points
	 * @return limits the draw's limits
	 */
	public synchronized Rectangle2D.Double findMinMax(){
		IMatrix m = new IMatrix(4,4);
		m = geoTransform.getMatrix();
		IMatrix pt = new IMatrix(1,4);
		
		double xMin = 0.0;
		double yMin = 0.0;
		double xMax = 0.0;
		double yMax = 0.0;
		
		for(int i=0;i<this.vertices.size();i++){
			pt.setElement(0,0,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).x);
			pt.setElement(0,1,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).y);
			pt.setElement(0,2,((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).z);
			pt.setElement(0,3,1);
			pt.mul(m);
			
			if(pt.getElement(0,0)<= xMin)
				xMin = pt.getElement(0,0);
			if(pt.getElement(0,1)<= yMin)
				yMin = pt.getElement(0,1);
			if(pt.getElement(0,0) >= xMax)
				xMax = pt.getElement(0,0);
			if(pt.getElement(0,1)>= yMax)
				yMax = pt.getElement(0,1);
		}
		
		yMin -= 0.05;
		yMax += 0.05;
		xMin -= 0.05;
		xMax += 0.05;
		
		//Rectangle2D.Double limits = new Rectangle2D.Double(xMin, yMin, xMax-xMin, yMax-yMin);
		Rectangle2D.Double limits = new Rectangle2D.Double(xMin, yMin, xMax, yMax);
		return limits;
	}
	
	public synchronized HalfEdgeModel getModelFemMesh(){
		return modelFemMesh;
	}
	
	public synchronized void setModelFemMesh(HalfEdgeModel modelFemMesh) {
		this.modelFemMesh = modelFemMesh;
	}
	
	public synchronized HalfEdgeModel getModelGaussMesh(){
		return modelGaussMesh;
	}
	
	public synchronized void setModelGaussMesh(HalfEdgeModel modelGaussMesh){
		this.modelGaussMesh = modelGaussMesh;
	}
	
//	**************************************************************************************
	
	public double findMaxGaussValue(){
		double vMax = 0;
		if(((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelGaussMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValues().containsKey(key)){
				if(vMax<(Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key)){
					vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key);
				}
			}
		}     
		return vMax;
	}
	
	public double findMinGaussValue(){
		double vMin = 0;
		if(((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMin = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMin = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelGaussMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelGaussMesh.getVerticesList().get(i)).valuesContainsKey(key)){
				double aux = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key);
				if(vMin>aux){
					vMin = aux;
				}
			}
		}
		return vMin;
	}
	
	public double findMaxDiscontinuosValue(){
		double vMax = 0;
		for(int i=0;i<this.modelFemMesh.getFacesList().size();i++){
			Face face = this.modelFemMesh.getFacesList().get(i);
			for (int j = 0; j < ((ArrayList)face.getValue(key)).size(); j++) {
				double value = (Double)((ArrayList)face.getValue(key)).get(j);
				if(vMax<value){
					vMax = value;
				}
			}
		}
		
		return vMax;
	}
	
	public double findMinDiscontinuosValue(){
		double vMin = 0;
		for(int i=0;i<this.modelFemMesh.getFacesList().size();i++){
			Face face = this.modelFemMesh.getFacesList().get(i);
			for (int j = 0; j < ((ArrayList)face.getValue(key)).size(); j++) {
				double value = (Double)((ArrayList)face.getValue(key)).get(j);
				if(vMin>value){
					vMin = value;
				}
			}
		}
		
		return vMin;
	}
	
	public double findMaxValue(){
		double vMax = 0;
		if(((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelGaussMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValues().containsKey(key)){
				if(vMax<(Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key)){
					vMax = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key);
				}
			}
		}     
		
		for (int i = 0; i < this.modelFemMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValues().containsKey(key)){
				if(vMax<(Double)((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValue(key)){
					vMax = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValue(key);
				}
			}
		} 
		
		return vMax;
	}
	
	public double findMinValue(){
		double vMin = 0;
		if(((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMin = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMin = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelGaussMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelGaussMesh.getVerticesList().get(i)).valuesContainsKey(key)){
				double aux = (Double)((Vertex)this.modelGaussMesh.getVerticesList().get(i)).getValue(key);
				if(vMin>aux){
					vMin = aux;
				}
			}
		}
		
		for (int i = 0; i < this.modelFemMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelFemMesh.getVerticesList().get(i)).valuesContainsKey(key)){
				double aux = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValue(key);
				if(vMin>aux){
					vMin = aux;
				}
			}
		}
		
		return vMin;
	}
	
	public void contourGaussDraw(Graphics2D g){
		resLimits = new LinkedList();
		//creating a polygon list
		this.triangulateGaussPoints();
		LinkedList facesTriangle = new LinkedList();
		
		double min = this.findMinGaussValue();
		double max = this.findMaxGaussValue();
		
		for (int i = 0; i < this.trianglesHalfEdgesList.size(); i++) {
			HalfEdgeModel triangulation = (HalfEdgeModel)trianglesHalfEdgesList.get(i); 
			facesTriangle = triangulation.getFacesList();
			for(int k=0;k<facesTriangle.size();k++){
				Face t = (Face)facesTriangle.get(k);
				Loop loop = (Loop)t.getLoopList().get(0);
				ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
				ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
				resLimits = calc.getRespLimits();
				for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
					HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
					calc.addVertex(he.getVertex().getCoords(),(Double)he.getVertex().getValue(key));
				}
				calc.end();
				polygonsList = new LinkedList();
				polygonsList = calc.getContoursMap();
				drawPlotContours(g);
			}
		}
	}
	
	public void contourElementsDraw(Graphics2D g){
		resLimits = new LinkedList();
		//creating a polygon list
		this.triangulate();
		LinkedList facesTriangle = new LinkedList();
		
		double min = this.findMinValue();
		double max = this.findMaxValue();
		
		for (int i = 0; i < this.trianglesHalfEdgesList.size(); i++) {
			HalfEdgeModel triangulation = (HalfEdgeModel)trianglesHalfEdgesList.get(i); 
			facesTriangle = triangulation.getFacesList();
			for(int k=0;k<facesTriangle.size();k++){
				Face t = (Face)facesTriangle.get(k);
				Loop loop = (Loop)t.getLoopList().get(0);
				ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
				ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
				resLimits = calc.getRespLimits();
				for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
					HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
					calc.addVertex(he.getVertex().getCoords(),(Double)he.getVertex().getValue(key));
				}
				calc.end();
				polygonsList = new LinkedList();
				polygonsList = calc.getContoursMap();
				drawPlotContours(g);
			}
		}
	}
	
	public void contourElementsDiscontinuosDraw(Graphics2D g){
		resLimits = new LinkedList();
		//creating a polygon list
		this.triangulate();
		LinkedList facesTriangle = new LinkedList();
		
		double min = this.findMinDiscontinuosValue();
		double max = this.findMaxDiscontinuosValue();
		
		for (int i = 0; i < this.trianglesHalfEdgesList.size(); i++) {
			HalfEdgeModel triangulation = (HalfEdgeModel)trianglesHalfEdgesList.get(i); 
			facesTriangle = triangulation.getFacesList();
			for(int k=0;k<facesTriangle.size();k++){
				Face t = (Face)facesTriangle.get(k);
				Loop loop = (Loop)t.getLoopList().get(0);
				ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
				ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
				resLimits = calc.getRespLimits();
				for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
					HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
					calc.addVertex(he.getVertex().getCoords(),(Double)he.getVertex().getValue(key));
					
				}
				calc.end();
				polygonsList = new LinkedList();
				polygonsList = calc.getContoursMap();
				drawPlotContours(g);
			}
		}
	}
	
	public void contourNodalsDiscontinuosDraw(Graphics2D g){
		pol = new LinkedList<LinkedList>();
		LinkedList polygons = new LinkedList();
		HalfEdgeModel triangulation = (HalfEdgeModel)modelFemMesh; 
		polygons = triangulation.getFacesList();
		
		double min = this.findMinDiscontinuosValue();
		double max = this.findMaxDiscontinuosValue();
		
		for(int k=0;k<polygons.size();k++){
			Face t = (Face)polygons.get(k);
			Loop loop = (Loop)t.getLoopList().get(0);
			ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
			resLimits = calc.getRespLimits();
			for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
				HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
				calc.addVertex(he.getVertex().getCoords(),(Double)((ArrayList)t.getValue(key)).get(j));
			}
			calc.end();
			this.polygonsList = new LinkedList();
			this.polygonsList = calc.getContoursMap();
			drawPlotContours(g);
		}
	}
	
	public double findMaxNodeValue(){
		double vMax = 0;
		if(((Vertex)this.modelFemMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMax = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMax = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelFemMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelFemMesh.getVerticesList().get(i)).valuesContainsKey(key)){
				double aux = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValue(key);
				if(vMax<aux){
					vMax = aux ;
				}
			}			
		}
		return vMax;
	}
	
	public double findMinNodeValue(){
		double vMin = 0;
		if(((Vertex)this.modelFemMesh.getVerticesList().get(0)).getValues().containsKey(key)){
			vMin = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(0)).getValue(key);
		}else{
			vMin = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(1)).getValue(key);
		}
		for (int i = 0; i < this.modelFemMesh.getVerticesList().size(); i++) {
			if(((Vertex)this.modelFemMesh.getVerticesList().get(i)).valuesContainsKey(key)){
				double aux = (Double)((Vertex)this.modelFemMesh.getVerticesList().get(i)).getValue(key);
				if(vMin>aux){
					vMin = aux;
				}
			}
		}
		return vMin;
	}
	
	public void contourNodeDraw(Graphics2D g){
		pol = new LinkedList<LinkedList>();
		LinkedList polygons = new LinkedList();
		HalfEdgeModel triangulation = (HalfEdgeModel)modelFemMesh; 
		polygons = triangulation.getFacesList();
		
		double min = this.findMinNodeValue();
		double max = this.findMaxNodeValue();
		
		for(int k=0;k<polygons.size();k++){
			Face t = (Face)polygons.get(k);
			Loop loop = (Loop)t.getLoopList().get(0);
			ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
			resLimits = calc.getRespLimits();
			for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
				HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
				calc.addVertex(he.getVertex().getCoords(),(Double)he.getVertex().getValue(key));
			}
			calc.end();
			this.polygonsList = new LinkedList();
			this.polygonsList = calc.getContoursMap();
			drawPlotContours(g);
		}
	}
	
	LinkedList<LinkedList> pol = new LinkedList<LinkedList>();
	
	public void contourNodeDrawOnMeshState(Graphics2D g){
		pol = new LinkedList<LinkedList>();
		LinkedList polygons = new LinkedList();
		HalfEdgeModel triangulation = (HalfEdgeModel)modelFemMeshState; 
		polygons = triangulation.getFacesList();
		
		double min = this.findMinNodeValue();
		double max = this.findMaxNodeValue();
		
		for(int k=0;k<polygons.size();k++){
			Face t = (Face)polygons.get(k);
			Loop loop = (Loop)t.getLoopList().get(0);
			ContourCalculator.setDigits(((PostpViewState)this.view.getViewState()).getFracDigits());
			ContourCalculator calc = new ContourCalculator(this.scaleColorsState.getColorsPalette(),max,min);
			resLimits = calc.getRespLimits();
			for (int j = 0; j < loop.getHalfEdgeList().size(); j++) {
				HalfEdge he = (HalfEdge)loop.getHalfEdgeList().get(j);
				Vertex v = he.getVertex();
				if(((Double)v.getValue((String)meshState.getXKey()))==null){
					v.setValue((String)meshState.getXKey(),new Double(0));
				}
				if(((Double)v.getValue((String)meshState.getYKey()))==null){
					v.setValue((String)meshState.getYKey(),new Double(0));
				}
				if(((Double)v.getValue((String)meshState.getZKey()))==null){
					v.setValue((String)meshState.getZKey(),new Double(0));
				}
				double x = v.getCoords().x + ((Double)v.getValue((String)meshState.getXKey())).doubleValue()*meshState.getXScale();
				double y = v.getCoords().y + ((Double)v.getValue((String)meshState.getYKey())).doubleValue()*meshState.getYScale();
				double z = v.getCoords().z + ((Double)v.getValue((String)meshState.getZKey())).doubleValue()*meshState.getZScale();
				IPoint3d p = new IPoint3d(x,y,z);
				calc.addVertex(p,(Double)v.getValue(key));
			}
			calc.end();
			this.polygonsMeshStateList = new LinkedList();
			this.polygonsMeshStateList = calc.getContoursMap();
			
			drawPlotContourOnMeshState(g);
		}
	}
	
	private synchronized void drawPlotContours(Graphics2D g){
		IMatrix m = geoTransform.getMatrix();
		for (int j = 0; j < this.polygonsList.size()-2; j++) {
			int[] ax = new int[((Contour)this.polygonsList.get(j)).getContoursVertices().size()];
			int[] ay = new int[((Contour)this.polygonsList.get(j)).getContoursVertices().size()];
			for(int i=0;i<((Contour)this.polygonsList.get(j)).getContoursVertices().size();i++){
				IMatrix pt = new IMatrix(1,4);
				IMatrix ptL = new IMatrix(1,4);
				pt.setElement(0,0,((IPoint3d)((Contour)this.polygonsList.get(j)).getContoursVertices().get(i)).x);
				pt.setElement(0,1,((IPoint3d)((Contour)this.polygonsList.get(j)).getContoursVertices().get(i)).y);
				pt.setElement(0,2,((IPoint3d)((Contour)this.polygonsList.get(j)).getContoursVertices().get(i)).z);
				pt.setElement(0,3,1);
				pt.mul(m);
				ptL = pt;
				ax[i] = ((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).x;
				ay[i] = ((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).y;
				
			}
			Polygon s = new Polygon(ax,ay,((Contour)this.polygonsList.get(j)).getContoursVertices().size()); 
			Color color = ((Color)this.scaleColorsState.getColorsPalette().get(j));
			g.setColor(color);
			g.setStroke(new BasicStroke((float)2.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			if(!this.scaleColorsState.isTransparent()){
				g.draw(s);
			}
			g.fill(s);
		}
	}
	
	private synchronized void drawPlotContourOnMeshState(Graphics2D g){
		IMatrix m = geoTransform.getMatrix();
		for (int j = 0; j < this.polygonsMeshStateList.size()-2; j++) {
			int[] ax = new int[((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().size()];
			int[] ay = new int[((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().size()];
			for(int i=0;i<((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().size();i++){
				IMatrix pt = new IMatrix(1,4);
				IMatrix ptL = new IMatrix(1,4);
				pt.setElement(0,0,((IPoint3d)((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().get(i)).x);
				pt.setElement(0,1,((IPoint3d)((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().get(i)).y);
				pt.setElement(0,2,((IPoint3d)((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().get(i)).z);
				pt.setElement(0,3,1);
				pt.mul(m);
				ptL = pt;
				ax[i] = ((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).x;
				ay[i] = ((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).y;
				
			}
			Polygon s = new Polygon(ax,ay,((Contour)this.polygonsMeshStateList.get(j)).getContoursVertices().size()); 
			Color color = ((Color)this.scaleColorsState.getColorsPalette().get(j));
			g.setColor(color);						
			g.setStroke(new BasicStroke((float)2.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			if(!this.scaleColorsState.isTransparent()){
				g.draw(s);
			}
			g.fill(s);
		}
	}
	
	private synchronized void drawGlobalAxis(Graphics2D g){
		Draw draw;
		//Drawing the global axis
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		if(this.view.getViewState().bgcolor.getRed()==0
				&&this.view.getViewState().bgcolor.getGreen()==0
				&&this.view.getViewState().bgcolor.getBlue()==0||
				this.view.getViewState().bgcolor==Color.BLACK
				||this.view.getViewState().bgcolor==Color.black){
			g.setColor(Color.lightGray);
		}else{
			g.setColor(Color.BLACK);
		}
		draw = new AxisDrawPerspective();
		draw.setAngle(0);
		((AxisDrawPerspective)draw).setLabel1("X");
		((AxisDrawPerspective)draw).setLabel2("Y");
		((AxisDrawPerspective)draw).setLabel3("Z");
		
		draw.setLocation(new Point(25,((PostpView)this.view).getDrawingArea().getHeight() -25));
		draw.draw(g);
	}
	 
	@SuppressWarnings("unused")
	private synchronized void drawLocalAxis(Graphics2D g){
		IMatrix m = geoTransform.getMatrix();
		
		Point auxVertex = new Point(this.view.getDrawingArea().getWidth()/2,this.view.getDrawingArea().getHeight()/2);
		IPoint3d auxVertex2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxVertex));
		
		// compute the delta value
		IPoint3d aux = new IPoint3d(auxVertex2.x, auxVertex2.y,auxVertex2.z);
		Point auxView = view.getDrawingArea().getViewPoint(aux.x,aux.y);
		Point auxView2 = new Point(auxView.x+10,auxView.y+10);
		IPoint3d aux2 = new IPoint3d(view.getDrawingArea().getWorldPoint(auxView2));
		double delta = aux2.distance(aux);
		
		//Drawing Local X axis
		IPoint3d p0 = new IPoint3d(auxVertex2.x, auxVertex2.y,auxVertex2.z);
		IPoint3d p1 = new IPoint3d(auxVertex2.x+2*delta-delta/3,auxVertex2.y-delta/10,auxVertex2.z);
		IPoint3d p2 = new IPoint3d(auxVertex2.x+2*delta-delta/3, auxVertex2.y+delta/10,auxVertex2.z);
		IPoint3d p3 = new IPoint3d(auxVertex2.x+2*delta, auxVertex2.y,auxVertex2.z);
		
		IMatrix pt = new IMatrix(1,4);
		pt.setElement(0,0,p0.x);
		pt.setElement(0,1,p0.y);
		pt.setElement(0,2,p0.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		double x = pt.getElement(0,0);
		double y = pt.getElement(0,1);
		//double z = pt.getElement(0,2);
		Point pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p1.x);
		pt.setElement(0,1,p1.y);
		pt.setElement(0,2,p1.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		Point pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p2.x);
		pt.setElement(0,1,p2.y);
		pt.setElement(0,2,p2.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		Point pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p3.x);
		pt.setElement(0,1,p3.y);
		pt.setElement(0,2,p3.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		Point pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(new Color(0,100,255));
		g.drawLine(pd0.x,pd0.y,pd3.x,pd3.y);
		g.drawLine(pd3.x,pd3.y,pd2.x,pd2.y);
		g.drawLine(pd3.x,pd3.y,pd1.x,pd1.y);
		
		
//		Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
//		draw.setRepresents(vertex);
//		nodalLoadsDraw.add(draw);
		
		//Drawing local Y Axis 
		p0 = new IPoint3d(auxVertex2.x, auxVertex2.y,auxVertex2.z);
		p1 = new IPoint3d(auxVertex2.x-delta/10,auxVertex2.y+2*delta-delta/3,auxVertex2.z);
		p2 = new IPoint3d(auxVertex2.x+delta/10, auxVertex2.y+2*delta-delta/3,auxVertex2.z);
		p3 = new IPoint3d(auxVertex2.x, auxVertex2.y+2*delta,auxVertex2.z);
		
		pt.setElement(0,0,p0.x);
		pt.setElement(0,1,p0.y);
		pt.setElement(0,2,p0.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//double z = pt.getElement(0,2);
		pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p1.x);
		pt.setElement(0,1,p1.y);
		pt.setElement(0,2,p1.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p2.x);
		pt.setElement(0,1,p2.y);
		pt.setElement(0,2,p2.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p3.x);
		pt.setElement(0,1,p3.y);
		pt.setElement(0,2,p3.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.RED);
		g.drawLine(pd0.x,pd0.y,pd3.x,pd3.y);
		g.drawLine(pd3.x,pd3.y,pd2.x,pd2.y);
		g.drawLine(pd3.x,pd3.y,pd1.x,pd1.y);
		
//		Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
//		draw.setRepresents(vertex);
//		nodalLoadsDraw.add(draw);		 
		
		p0 = new IPoint3d(auxVertex2.x, auxVertex2.y,auxVertex2.z);
		p1 = new IPoint3d(auxVertex2.x-delta/5,auxVertex2.y,auxVertex2.z+delta-delta/5);
		p2 = new IPoint3d(auxVertex2.x+delta/5, auxVertex2.y,auxVertex2.z+delta-delta/5);
		p3 = new IPoint3d(auxVertex2.x, auxVertex2.y,auxVertex2.z+delta);
		IPoint3d p4= new IPoint3d(auxVertex2.x,auxVertex2.y-delta/5,auxVertex2.z+delta-delta/5);
		IPoint3d p5 = new IPoint3d(auxVertex2.x, auxVertex2.y+delta/5,auxVertex2.z+delta-delta/5);
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p0.x);
		pt.setElement(0,1,p0.y);
		pt.setElement(0,2,p0.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//double z = pt.getElement(0,2);
		pd0 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p1.x);
		pt.setElement(0,1,p1.y);
		pt.setElement(0,2,p1.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd1 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p2.x);
		pt.setElement(0,1,p2.y);
		pt.setElement(0,2,p2.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd2 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p3.x);
		pt.setElement(0,1,p3.y);
		pt.setElement(0,2,p3.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		pd3 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p4.x);
		pt.setElement(0,1,p4.y);
		pt.setElement(0,2,p4.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		Point pd4 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		pt = new IMatrix(1,4);
		pt.setElement(0,0,p5.x);
		pt.setElement(0,1,p5.y);
		pt.setElement(0,2,p5.z);
		pt.setElement(0,3,1);
		pt.mul(m);
		x = pt.getElement(0,0);
		y = pt.getElement(0,1);
		//z = pt.getElement(0,2);
		Point pd5 = new Point(view.getDrawingArea().getViewPoint(x,y));
		
		g.setStroke(new BasicStroke((float)1.0, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.GREEN);
		g.drawLine(pd0.x,pd0.y,pd3.x,pd3.y);
		g.drawLine(pd3.x,pd3.y,pd2.x,pd2.y);
		g.drawLine(pd3.x,pd3.y,pd1.x,pd1.y);
		g.drawLine(pd3.x,pd3.y,pd4.x,pd4.y);
		g.drawLine(pd3.x,pd3.y,pd5.x,pd5.y);
		
//		Draw draw = new NodalLoadDraw.X(pd0,pd1,pd2, pd3);
//		draw.setRepresents(vertex);
//		nodalLoadsDraw.add(draw);		
		
		
	}
	
	private synchronized void drawFemMeshFaces(Graphics2D g){
		Draw draw;
		//Drawing the faces
		ArrayList<Face> selectedFaces = new ArrayList<Face>();
		ArrayList<Draw> selectedFacesDraw = new ArrayList<Draw>();
		for(int k=0;k<this.facesDraw.size();k++){
			FaceDraw face = ((FaceDraw)this.facesDraw.get(k));
			//get the selected faces to be draw later
			if(face.isSelected()){
				selectedFaces.add((Face)this.faces.get(k));
				selectedFacesDraw.add(face);
			}else if(!face.isSelected()){
				//drawing the unselected faces
				face.setFaceColor(edgeState.getLineColor());
				face.setFillColor(faceState.getFillColor());
				
				if(faceState.getFillType().equals("NONE")){
					face.setFillType((byte)1);
				}
				if(faceState.getFillType().equals("Transparent")){
					face.setFillType((byte)2);
					face.setIntensity(faceState.getIntensity());
				}
				if(faceState.getFillType().equals("Opaque")){
					face.setFillType((byte)3);
				}
				face.setLineWidth(this.edgeState.getLineWindth());
				face.draw(g);
			}
		}
		
		//Drawing the selected faces
		if(this.selections.size()!=0){
			for(int k=0;k<selectedFaces.size();k++){
				FaceDraw face = ((FaceDraw)selectedFacesDraw.get(k));
				face.setFaceColor(edgeState.getLineColor());
				face.setFillColor(faceState.getFillColor());
				if(faceState.getFillType().equals("NONE")){
					face.setFillType((byte)1);
				}
				if(faceState.getFillType().equals("Transparent")){
					face.setFillType((byte)2);
					face.setIntensity(faceState.getIntensity());
				}
				if(faceState.getFillType().equals("Opaque")){
					face.setFillType((byte)3);
				}
				face.setLineWidth(this.edgeState.getLineWindth());
				face.draw(g);
			}
		}
		
		//drawing the faces labels
		if(this.faceState.isLabelOn()){
			for(int k=0;k<this.faces.size();k++){
				if(faceState.isLabelOn()){
					StringDraw label = new StringDraw();
					Point locT = ((PostpView)this.view).getDrawingArea().getViewPoint(center((Face)this.faces.get(k))[0],center((Face)this.faces.get(k))[1]);
					label.setString(((Face)this.faces.get(k)).getId());
					label.setCentre(locT);
					label.setLocation(locT);
					label.setFontType(faceState.getTextFont());
					label.setFontSize(faceState.getTextSize());
					label.setFontStyle(faceState.getTextStyle());
					draw = (Draw)label;
					g.setColor(faceState.getLabelColor());
					draw.draw(g);
				}
			}
		}
		
	}
	
	private synchronized void drawTriangulation(Graphics2D g){
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		IMatrix m = geoTransform.getMatrix();
		LinkedList verticesList = new LinkedList();
		
		//Drawing the faces
		ArrayList<Point> facePoints = new ArrayList<Point>();
		int cont = 0; 
		for (int i = 0; i < trianglesHalfEdgesList.size(); i++) {
			HalfEdgeModel triangulation = (HalfEdgeModel)trianglesHalfEdgesList.get(i); 
			this.tfaces = triangulation.getFacesList(); 
			for(int k=0;k<this.tfaces.size();k++){
				verticesList = triangulation.getVerticesFace((Face)this.tfaces.get(k));
				facePoints= new ArrayList<Point>();
				for(int j=0;j<verticesList.size();j++){
					IMatrix pt = new IMatrix(1,4);
					IMatrix ptL = new IMatrix(1,4);
					//IMatrix mR = new IMatrix(4,4);
					pt.setElement(0,0,((Vertex)verticesList.get(j)).getCoords().x);
					pt.setElement(0,1,((Vertex)verticesList.get(j)).getCoords().y);
					pt.setElement(0,2,((Vertex)verticesList.get(j)).getCoords().z);
					pt.setElement(0,3,1);
					pt.mul(m);
					ptL = pt; 
					facePoints.add(new Point(((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).x,
							((PostpView)this.view).getDrawingArea().getViewPoint(ptL.getElement(0,0),ptL.getElement(0,1)).y));
					FaceDraw face = new FaceDraw(facePoints,tfaces.get(k));
					face.setFaceColor(Color.GRAY);
					face.setLineWidth(0.5f);
					face.setFillType((byte)1);
					face.setFillOn(false);
					face.setBoundaryOn(true);
					face.draw(g);
					cont++;
					if(cont==36){
						cont=0;
					}
				}
			}
		}
	}
	
	@SuppressWarnings("unused")
	private ArrayList color(){
		Color c1 =new Color(0,0,12);
		Color c2 =new Color(0,0,32);
		Color c3 =new Color(0,0,52);
		Color c4 =new Color(0,0,72);
		Color c5 =new Color(0,0,92);
		Color c6 =new Color(0,0,112);
		Color c7 =new Color(0,0,132);
		Color c8 =new Color(0,0,152);
		Color c9 =new Color(0,0,172);
		Color c10 =new Color(255,0,0);
		Color c11 =new Color(240,0,0);
		Color c12 =new Color(225,0,0);
		Color c13 =new Color(205,0,0);
		Color c14 =new Color(190,0,0);
		Color c15 =new Color(175,0,0);
		Color c16 =new Color(160,0,0);
		Color c17 =new Color(145,0,0);
		Color c18 =new Color(130,0,0);
		Color c19 =new Color(250,250,250);
		Color c20 =new Color(230,230,230);
		Color c21 =new Color(210,210,210);
		Color c22 =new Color(190,190,190);
		Color c23 =new Color(170,170,170);
		Color c24 =new Color(150,150,150);
		Color c25 =new Color(130,130,130);
		Color c26 =new Color(110,110,110);
		Color c27 =new Color(90,90,90);
		Color c28 =new Color(0,250,0);
		Color c29 =new Color(0,230,0);
		Color c30 =new Color(0,210,0);
		Color c31 =new Color(0,190,0);
		Color c32 =new Color(0,170,0);
		Color c33 =new Color(0,150,0);
		Color c34 =new Color(0,130,0);
		Color c35 =new Color(0,110,0);
		Color c36 =new Color(0,90,0);
		
		ArrayList<Color> colors = new ArrayList<Color>();
		colors.add(c1);
		colors.add(c2);
		colors.add(c3);
		colors.add(c4);
		colors.add(c5);
		colors.add(c6);
		colors.add(c7);
		colors.add(c8);
		colors.add(c9);
		colors.add(c10);
		colors.add(c11);
		colors.add(c12);
		colors.add(c13);
		colors.add(c14);
		colors.add(c15);
		colors.add(c16);
		colors.add(c17);
		colors.add(c18);
		colors.add(c19);
		colors.add(c20);
		colors.add(c21);
		colors.add(c22);
		colors.add(c23);
		colors.add(c24);
		colors.add(c25);
		colors.add(c26);
		colors.add(c27);
		colors.add(c28);
		colors.add(c29);
		colors.add(c30);
		colors.add(c31);
		colors.add(c32);
		colors.add(c33);
		colors.add(c34);
		colors.add(c35);
		colors.add(c36);
		
		return colors;
	}
	
	@SuppressWarnings("unused")
	private synchronized void drawFemMeshEdges(Graphics2D g){
		Draw draw;
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		IMatrix m = geoTransform.getMatrix();
		
		g.setStroke(new BasicStroke((float)edgeState.getLineWindth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(edgeState.getLineColor());
		
		for(int i=0;i<this.edges.size();i++){
			IMatrix pointS = new IMatrix(1,4);
			IMatrix pointE = new IMatrix(1,4);
			IMatrix pointLS = new IMatrix(1,4);
			IMatrix pointLE = new IMatrix(1,4);
			
			pointS.setElement(0,0,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).x);
			pointS.setElement(0,1,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).y);
			pointS.setElement(0,2,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).z);
			pointS.setElement(0,3,1);
			pointS.mul(m);
			pointLS = pointS;
			
			pointE.setElement(0,0,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).x);
			pointE.setElement(0,1,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).y);
			pointE.setElement(0,2,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).z);
			pointE.setElement(0,3,1);
			pointE.mul(m);
			pointLE = pointE;
			
			LineDraw line = new LineDraw (((PostpView)this.view).getDrawingArea().getViewPoint(
					pointLS.getElement(0,0),pointLS.getElement(0,1)),
					((PostpView)this.view).getDrawingArea().getViewPoint(
							pointLE.getElement(0,0),pointLE.getElement(0,1)));
			
			line.draw(g);
			
		}
		
		//Drawing the label of the edges
		for(int k=0;k<this.edges.size();k++){
			if(edgeState.isLabelOn()){
				StringDraw label = new StringDraw();
				Point locT = ((PostpView)this.view).getDrawingArea().getViewPoint(center((Edge)this.edges.get(k))[0],
						center((Edge)this.edges.get(k))[1]);
				label.setString(((Edge)this.edges.get(k)).getId());
				label.setCentre(locT);
				label.setLocation(locT);
				label.setFontType(edgeState.getTextFont());
				label.setFontSize(edgeState.getTextSize());
				label.setFontStyle(edgeState.getTextStyle());
				draw = (Draw)label;
				g.setColor(edgeState.getLabelColor());
				draw.draw(g);
			}
		}
		
	}
	
	private synchronized void drawFemMeshVertex(Graphics2D g){
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		nf = NumberFormat.getNumberInstance();
		
		//Drawing the vertices of fem mesh
		g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(vertexState.getMarkColor()); 
		
		for(int i=0;i<this.vertices.size();i++){
			MarkDraw point = ((MarkDraw)vertexDraw.get(i));
			point.setMarkColor(vertexState.getMarkColor());
			point.setSize(new Dimension(vertexState.getMarkSize(),vertexState.getMarkSize()));
			
			if(vertexState.isLabelOn() && !vertexState.isCoordsOn()){
				point.setLabelColor(vertexState.getLabelColor());
				String lb = ((Vertex)this.vertices.get(i)).getId();
				point.setLabelOn(true);
				point.setLabel(lb);
				point.setLabelFont(vertexState.getTextFont());
				point.setLabelSize(vertexState.getTextSize());
				point.setLabelStyle(vertexState.getTextStyle());
			}
			if(!vertexState.isLabelOn() && vertexState.isCoordsOn()){
				point.setLabelColor(vertexState.getLabelColor());
				String lb = ("("+nf.format(((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).x)+";"+nf.format(((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).y)+")");
				point.setLabelOn(true);
				point.setLabel(lb);
				point.setLabelFont(vertexState.getTextFont());
				point.setLabelSize(vertexState.getTextSize());
				point.setLabelStyle(vertexState.getTextStyle());
			}
			if(vertexState.isLabelOn()&& vertexState.isCoordsOn()){
				point.setLabelColor(vertexState.getLabelColor());
				String lb = ((Vertex)this.vertices.get(i)).getId()+" - "+ "("+nf.format(((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).x)+";"+nf.format(((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).y)+")";
				point.setLabelOn(true);
				point.setLabel(lb);
				point.setLabelFont(vertexState.getTextFont());
				point.setLabelSize(vertexState.getTextSize());
				point.setLabelStyle(vertexState.getTextStyle());
			}
			if(!vertexState.isLabelOn()&& !vertexState.isCoordsOn()){
				point.setLabelOn(false);
			}
			
			
			point.draw(g);
		}
	}
	
	@SuppressWarnings("unused")
	private synchronized void drawTriangulationByEdges(Graphics2D g){
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		
		nf = NumberFormat.getNumberInstance();
		IMatrix m = geoTransform.getMatrix();
		
		g.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.lightGray);
		
		for(int i=0;i<this.triangulateEdges.size();i++){
			Edge edge = (Edge)this.triangulateEdges.get(i);
			
			double vsx = edge.getVStart().getCoords().x;
			double vsy = edge.getVStart().getCoords().y;
			double vsz = edge.getVStart().getCoords().z;
			double vex = edge.getVEnd().getCoords().x;
			double vey = edge.getVEnd().getCoords().y;
			double vez = edge.getVEnd().getCoords().z;
			
			IMatrix pointS = new IMatrix(1,4);
			IMatrix pointE = new IMatrix(1,4);
			IMatrix pointLS = new IMatrix(1,4);
			IMatrix pointLE = new IMatrix(1,4);
			pointS.setElement(0,0,vsx);
			pointS.setElement(0,1,vsy);
			pointS.setElement(0,2,vsz);
			pointS.setElement(0,3,1);
			pointS.mul(m);
			pointLS = pointS;
			
			pointE.setElement(0,0,vex);
			pointE.setElement(0,1,vey);
			pointE.setElement(0,2,vez);
			pointE.setElement(0,3,1);
			pointE.mul(m);
			pointLE = pointE;
			
			LineDraw line = new LineDraw (((PostpView)this.view).getDrawingArea().getViewPoint(
					pointLS.getElement(0,0),pointLS.getElement(0,1)),
					((PostpView)this.view).getDrawingArea().getViewPoint(
							pointLE.getElement(0,0),pointLE.getElement(0,1)));
			
			line.draw(g);
			
		}
		
	}  
	
	private synchronized void drawDeformedFemMeshFaces(Graphics2D g){
		g.setStroke(new BasicStroke((float)this.edgeState.getLineWindth(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		//Drawing the deformed faces
		if(meshState.isMeshStateOnOff()){  
			for(int k=0;k<this.deformedFacesDraw.size();k++){
				FaceDraw deformedFace = ((FaceDraw)this.deformedFacesDraw.get(k));
				deformedFace.setFaceColor(edgeState.getLineStateColor());
				deformedFace.setFillColor(this.faceState.getFillStateColor());
				deformedFace.setLineWidth(this.edgeState.getLineWindth());
				if(faceState.getFillStateType().equals("NONE")){
					deformedFace.setFillType((byte)1);
				}
				if(faceState.getFillStateType().equals("Transparent")){
					deformedFace.setFillType((byte)2);
					deformedFace.setIntensity(this.faceState.getIntensityState());
				}
				if(faceState.getFillStateType().equals("Opaque")){
					deformedFace.setFillType((byte)3);
				}
				deformedFace.draw(g);
			}
		}
		
	}
	
	@SuppressWarnings("unused")
	private synchronized void drawDeformedFemMeshEdges(Graphics2D g){
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		meshState = ((PostpViewState)((PostpView)this.view).getViewState()).getMeshStateViewState();
		edgeState = ((PostpViewState)((PostpView)this.view).getViewState()).getEdgeViewState();
		faceState = ((PostpViewState)((PostpView)this.view).getViewState()).getFaceViewState();
		vertexState = ((PostpViewState)((PostpView)this.view).getViewState()).getVertexViewState();
		
		nf = NumberFormat.getNumberInstance();
		IMatrix m = geoTransform.getMatrix();
		g.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.RED);
		
		LinkedList verticesTest = this.modelFemMesh.getVerticesList();
		for(int i=0;i<this.modelFemMesh.getVerticesList().size();i++){
			Vertex v = (Vertex)verticesTest.get(i);
			if(((Vertex)v).getValue((String)meshState.getXKey())== null){
				((Vertex)verticesTest.get(i)).setValue((String)meshState.getXKey(),new Double(0));
			}
			if(((Vertex)v).getValue((String)meshState.getYKey())== null){
				((Vertex)verticesTest.get(i)).setValue((String)meshState.getYKey(),new Double(0));
			}
			if(((Vertex)v).getValue((String)meshState.getZKey())== null){
				((Vertex)verticesTest.get(i)).setValue((String)meshState.getZKey(),new Double(0));
			}
		}
		
		//drawing the deformed edges 
		g.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.RED);
		view.getDrawingArea().setBackground(this.view.getViewState().bgcolor);
		double startX = 0;
		double startY = 0;
		double startZ = 0;
		double endX = 0;
		double endY = 0;
		double endZ = 0;
		
		for(int i=0;i<this.edges.size();i++){
			if(((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getXKey())!= null){
				startX = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getXKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVStart()).setValue((String)meshState.getXKey(),new Double(0));
				startX = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getXKey())).doubleValue();
			}
			if(((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getYKey())!= null){
				startY = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getYKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVStart()).setValue((String)meshState.getYKey(),new Double(0));
				startY = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getYKey())).doubleValue();
			}
			if(((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getZKey())!= null){
				startZ = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getZKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVStart()).setValue((String)meshState.getZKey(),new Double(0));
				startZ = ((Double)((Vertex)((Edge)edges.get(i)).getVStart()).getValue((String)meshState.getZKey())).doubleValue();
			}
			if(((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getXKey())!= null){
				endX = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getXKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVEnd()).setValue((String)meshState.getXKey(),new Double(0));
				endX = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getXKey())).doubleValue(); 
			}
			if(((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getYKey())!= null){
				endY = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getYKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVEnd()).setValue((String)meshState.getYKey(),new Double(0));
				endY = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getYKey())).doubleValue(); 
			}
			if(((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getZKey())!= null){
				endZ = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getZKey())).doubleValue();
			}else{
				((Vertex)((Edge)edges.get(i)).getVEnd()).setValue((String)meshState.getZKey(),new Double(0));
				endZ = ((Double)((Vertex)((Edge)edges.get(i)).getVEnd()).getValue((String)meshState.getZKey())).doubleValue(); 
			}
			
			IMatrix pointS = new IMatrix(1,4);
			IMatrix pointE = new IMatrix(1,4);
			IMatrix pointLS = new IMatrix(1,4);
			IMatrix pointLE = new IMatrix(1,4);
			
			pointS.setElement(0,0,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).x+ startX*meshState.getXScale());
			pointS.setElement(0,1,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).y+ startY*meshState.getYScale());
			pointS.setElement(0,2,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVStart()).getCoords()).z+ startZ*meshState.getZScale());
			pointS.setElement(0,3,1);
			pointS.mul(m);
			pointLS = pointS;
			
			pointE.setElement(0,0,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).x+ endX*meshState.getXScale());
			pointE.setElement(0,1,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).y+ endY*meshState.getYScale());
			pointE.setElement(0,2,((IPoint3d)((Vertex)((Edge)edges.get(i)).getVEnd()).getCoords()).z+ endZ*meshState.getZScale());
			pointE.setElement(0,3,1);
			pointE.mul(m);
			pointLE = pointE;
			
			LineDraw line = new LineDraw (((PostpView)this.view).getDrawingArea().getViewPoint(
					pointLS.getElement(0,0),pointLS.getElement(0,1)),
					((PostpView)this.view).getDrawingArea().getViewPoint(
							pointLE.getElement(0,0),pointLE.getElement(0,1)));
			line.draw(g);
			
		}
		
	}
	
	private synchronized void drawDeformedFemMeshVertex(Graphics2D g){
		g.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		//Drawing the vertices
		for(int i=0;i<this.deformedVertexDraw.size();i++){
			MarkDraw point = ((MarkDraw)deformedVertexDraw.get(i));
			point.setMarkColor(vertexState.getMarkColor());
			point.setSize(new Dimension(vertexState.getMarkSize(),vertexState.getMarkSize()));
			Point2D pointLoc = ((PostpView)this.view).getDrawingArea().getWorldPoint(point.getLocation());
			String lb = ((Vertex)this.vertices.get(i)).getId()+" - ("+nf.format(pointLoc.getX())+";"+nf.format(pointLoc.getY())+")";
			point.setLabelOn(false);
			point.setLabel(lb);
			point.setLabelSize(15);
			g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
			g.setColor(Color.DARK_GRAY);
			point.draw(g);
		}
	}
	
	private synchronized void drawGaussMeshVertex(Graphics2D g){
		nf = NumberFormat.getNumberInstance();
		//Drawing the gaussMarks
		g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
		g.setColor(Color.CYAN); 
		for(int i=0;i<this.gaussVertex.size();i++){
			MarkDraw gaussMark = ((MarkDraw)gaussVertexDraw.get(i));
			gaussMark.setMarkColor(Color.CYAN);
			gaussMark.setType(MarkDraw.TIMES);
			
			if(gaussVertexState.isLabelOn() & !gaussVertexState.isCoordsOn()){
				gaussMark.setLabelColor(gaussVertexState.getLabelColor());
				String lb = ((Vertex)this.vertices.get(i)).getId();
				gaussMark.setLabelOn(true);
				gaussMark.setLabel(lb);
				gaussMark.setLabelFont(gaussVertexState.getTextFont());
				gaussMark.setLabelSize(gaussVertexState.getTextSize());
				gaussMark.setLabelStyle(gaussVertexState.getTextStyle());
			}
			if(!gaussVertexState.isLabelOn() & gaussVertexState.isCoordsOn()){
				gaussMark.setLabelColor(gaussVertexState.getLabelColor());
				String lb = ("("+nf.format(((IPoint3d)((Vertex)this.vertices.get(i)).getCoords()).x)+";"+nf.format(((IPoint3d)((Vertex)this.gaussVertex.get(i)).getCoords()).y)+")");
				gaussMark.setLabelOn(true);
				gaussMark.setLabel(lb);
				gaussMark.setLabelFont(gaussVertexState.getTextFont());
				gaussMark.setLabelSize(gaussVertexState.getTextSize());
				gaussMark.setLabelStyle(gaussVertexState.getTextStyle());
			}
			if(gaussVertexState.isLabelOn()& gaussVertexState.isCoordsOn()){
				gaussMark.setLabelColor(gaussVertexState.getLabelColor());
				String lb = ((Vertex)this.gaussVertex.get(i)).getId()+" - "+ "("+nf.format(((IPoint3d)((Vertex)this.gaussVertex.get(i)).getCoords()).x)+";"+nf.format(((IPoint3d)((Vertex)this.gaussVertex.get(i)).getCoords()).y)+")";
				gaussMark.setLabelOn(true);
				gaussMark.setLabel(lb);
				gaussMark.setLabelFont(gaussVertexState.getTextFont());
				gaussMark.setLabelSize(gaussVertexState.getTextSize());
				gaussMark.setLabelStyle(gaussVertexState.getTextStyle());
			}
			gaussMark.draw(g);
		} 
		
	}
	
//	**************************************************************************************    
}// end of this class











































